1 | "use strict";
|
2 | var fs = require("fs");
|
3 | var schema_1 = require("graphql/type/schema");
|
4 | var graphql_1 = require("graphql");
|
5 | exports.introspectionFromExport = function (file) {
|
6 | return new Promise(function (resolve, reject) {
|
7 | if (fs.existsSync(file)) {
|
8 | try {
|
9 | var schema = require(file);
|
10 | if (schema && schema instanceof schema_1.GraphQLSchema) {
|
11 | resolve(graphql_1.graphql(schema, graphql_1.introspectionQuery).then(function (res) { return res.data; }));
|
12 | }
|
13 | else {
|
14 | reject(new Error("Invalid export from export file " + file + ", make sure to default export your GraphQLSchema object!"));
|
15 | }
|
16 | }
|
17 | catch (e) {
|
18 | reject(e);
|
19 | }
|
20 | }
|
21 | else {
|
22 | reject("Unable to locate introspection export file: " + file);
|
23 | }
|
24 | });
|
25 | };
|
26 |
|
\ | No newline at end of file |