Skip to content

Instantly share code, notes, and snippets.

@nwillc
Last active November 10, 2016 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwillc/fbe4939dfcbf91ddd8da2a172584dc28 to your computer and use it in GitHub Desktop.
Save nwillc/fbe4939dfcbf91ddd8da2a172584dc28 to your computer and use it in GitHub Desktop.
var Graphql = function (url, query) {
"use strict";
var _this = this;
this.url = url;
this.query = query;
this.variables = {};
this.toString = function () {
return JSON.stringify(_this);
};
this.execute = function (consumer) {
console.log("GraphQL Request: " + _this);
$.ajax({
url: _this.url,
async: true,
method: "POST",
contentType: "application/json",
data: _this.toString(),
dataType: "json",
success: function (response) {
if (response.errors != undefined) {
console.log("GraphQL Errors: " + JSON.stringify(response.errors));
}
consumer(response);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Request failed: " + textStatus);
console.log(errorThrown);
}
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment