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