1 | "use strict";
|
2 | var introspectionQuery_1 = require("graphql/utilities/introspectionQuery");
|
3 | var request = require("request");
|
4 | exports.introspectionFromUrl = function (url, headers) {
|
5 | var splittedHeaders = headers.map(function (header) {
|
6 | var _a = header.split(/\s*:\s*/), name = _a[0], value = _a[1];
|
7 | return _b = {},
|
8 | _b[name] = value,
|
9 | _b;
|
10 | var _b;
|
11 | });
|
12 | var extraHeaders = {};
|
13 | if (splittedHeaders.length > 0) {
|
14 | extraHeaders = splittedHeaders.reduce(function (a, b) {
|
15 | return Object.assign({}, a, b);
|
16 | });
|
17 | }
|
18 | return new Promise(function (resolve, reject) {
|
19 | request.post({
|
20 | url: url,
|
21 | json: {
|
22 | query: introspectionQuery_1.introspectionQuery.replace('locations', '')
|
23 | },
|
24 | headers: Object.assign({
|
25 | 'Accept': 'application/json',
|
26 | 'Content-Type': 'application/json'
|
27 | }, extraHeaders)
|
28 | }, function (err, response, body) {
|
29 | if (err) {
|
30 | reject(err);
|
31 | return;
|
32 | }
|
33 | var bodyJson = body.data;
|
34 | if (!bodyJson || (body.errors && body.errors.length > 0)) {
|
35 | reject('Unable to download schema from remote: ' + body.errors.map(function (item) { return item.message; }).join(', '));
|
36 | return;
|
37 | }
|
38 | resolve(bodyJson);
|
39 | });
|
40 | });
|
41 | };
|
42 |
|
\ | No newline at end of file |