|
31 | 31 | }) |
32 | 32 | } |
33 | 33 |
|
34 | | - function __request(method, url, headers, data, callback) { |
35 | | - var body = "query=" + encodeURIComponent(data.query) + "&variables=" + encodeURIComponent(JSON.stringify(data.variables)) |
| 34 | + function __request(method, url, headers, data, asJson, callback) { |
| 35 | + if (asJson) { |
| 36 | + var body = JSON.stringify({query: data.query, variables: data.variables}); |
| 37 | + } else { |
| 38 | + var body = "query=" + encodeURIComponent(data.query) + "&variables=" + encodeURIComponent(JSON.stringify(data.variables)) |
| 39 | + } |
36 | 40 | if (typeof XMLHttpRequest != 'undefined') { |
37 | 41 | var xhr = new XMLHttpRequest |
38 | 42 | xhr.open(method, url, true) |
39 | | - xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded') |
| 43 | + xhr.setRequestHeader('Content-Type', (asJson ? 'application/json' : 'application/x-www-form-urlencoded')) |
40 | 44 | xhr.setRequestHeader('Accept', 'application/json') |
41 | 45 | for (var key in headers) { xhr.setRequestHeader(key, headers[key]) } |
42 | 46 | xhr.onerror = function () { callback(xhr, xhr.status) } |
|
51 | 55 | path: uri.path, |
52 | 56 | method: "POST", |
53 | 57 | headers: __extend({ |
54 | | - 'Content-type': 'application/x-www-form-urlencoded', |
| 58 | + 'Content-type': (asJson ? 'application/json' : 'application/x-www-form-urlencoded'), |
55 | 59 | 'Accept': 'application/json' |
56 | 60 | }, headers) |
57 | 61 | }, function (response) { |
|
241 | 245 | __request(that.options.method || "post", url, headers, { |
242 | 246 | query: fragmentedQuery, |
243 | 247 | variables: that.cleanAutoDeclareAnnotations(variables) |
244 | | - }, function (response, status) { |
| 248 | + }, !!this.options.asJSON, function (response, status) { |
245 | 249 | if (status == 200) { |
246 | 250 | if (response.errors) { |
247 | 251 | reject(response.errors) |
|
0 commit comments