1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var fs = require("fs");
|
4 | var path = require("path");
|
5 | exports.schemaFromExport = function (file) {
|
6 | console.log("Loading GraphQL Introspection from JavaScript ES6 export: " + file + "...");
|
7 | return new Promise(function (resolve, reject) {
|
8 | var fullPath = path.isAbsolute(file) ? file : path.resolve(process.cwd(), file);
|
9 | if (fs.existsSync(fullPath)) {
|
10 | try {
|
11 | var exports_1 = require(fullPath);
|
12 | if (exports_1) {
|
13 | var schema = exports_1.default || exports_1.schema;
|
14 | if (schema) {
|
15 | resolve(schema);
|
16 | }
|
17 | else {
|
18 | reject(new Error("Invalid export from export file " + fullPath + ": missing default export or 'schema' export!"));
|
19 | }
|
20 | }
|
21 | else {
|
22 | reject(new Error("Invalid export from export file " + fullPath + ": empty export!"));
|
23 | }
|
24 | }
|
25 | catch (e) {
|
26 | reject(e);
|
27 | }
|
28 | }
|
29 | else {
|
30 | reject("Unable to locate introspection from export file: " + fullPath);
|
31 | }
|
32 | });
|
33 | };
|
34 |
|
\ | No newline at end of file |