1 | "use strict";
|
2 | var request = require("request");
|
3 | var introspectionQuery_1 = require("graphql/utilities/introspectionQuery");
|
4 | exports.introspectionFromUrl = function (url) {
|
5 | return new Promise(function (resolve, reject) {
|
6 | request.post({
|
7 | url: url,
|
8 | json: {
|
9 | query: introspectionQuery_1.introspectionQuery
|
10 | },
|
11 | headers: {
|
12 | 'Accept': 'application/json',
|
13 | 'Content-Type': 'application/json'
|
14 | }
|
15 | }, function (err, response, body) {
|
16 | if (err) {
|
17 | reject(err);
|
18 | return;
|
19 | }
|
20 | var bodyJson = body.data;
|
21 | if (!bodyJson || (bodyJson.errors && bodyJson.errors.length > 0)) {
|
22 | reject('Unable to download schema from remote: ' + bodyJson.errors.map(function (item) { return item.message; }).join(', '));
|
23 | return;
|
24 | }
|
25 | resolve(bodyJson);
|
26 | });
|
27 | });
|
28 | };
|
29 |
|
\ | No newline at end of file |