Last active
November 10, 2016 03:42
-
-
Save nwillc/fbe4939dfcbf91ddd8da2a172584dc28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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