1 | "use strict";
|
2 | var __assign = (this && this.__assign) || Object.assign || function(t) {
|
3 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4 | s = arguments[i];
|
5 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6 | t[p] = s[p];
|
7 | }
|
8 | return t;
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | var graphql_codegen_core_1 = require("graphql-codegen-core");
|
12 | var request = require("request");
|
13 | exports.introspectionFromUrl = function (url, headers) {
|
14 | graphql_codegen_core_1.logger.info("Loading GraphQL Introspection from remote: " + url + "...");
|
15 | var splittedHeaders = (headers || [])
|
16 | .map(function (header) {
|
17 | var _a;
|
18 | var result = header.match(/^(.*?)[:=]{1}(.*?)$/);
|
19 | if (result && result.length > 0) {
|
20 | var name = result[1];
|
21 | var value = result[2];
|
22 | return _a = {},
|
23 | _a[name] = value,
|
24 | _a;
|
25 | }
|
26 | return null;
|
27 | })
|
28 | .filter(function (item) { return item; });
|
29 | var extraHeaders = __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, splittedHeaders.reduce(function (prev, item) { return (__assign({}, prev, item)); }, {}));
|
30 | graphql_codegen_core_1.debugLog("Executing POST to " + url + " with headers: ", extraHeaders);
|
31 | return new Promise(function (resolve, reject) {
|
32 | request.post({
|
33 | url: url,
|
34 | json: {
|
35 | query: graphql_codegen_core_1.introspectionQuery.replace('locations', '')
|
36 | },
|
37 | headers: extraHeaders
|
38 | }, function (err, response, body) {
|
39 | if (err) {
|
40 | reject(err);
|
41 | return;
|
42 | }
|
43 | var bodyJson = body.data;
|
44 | if (!bodyJson || (body.errors && body.errors.length > 0)) {
|
45 | reject('Unable to download schema from remote: ' + body.errors.map(function (item) { return item.message; }).join(', '));
|
46 | return;
|
47 | }
|
48 | resolve(bodyJson);
|
49 | });
|
50 | });
|
51 | };
|
52 |
|
\ | No newline at end of file |