1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var fs = require("fs");
|
4 | var graphql_codegen_core_1 = require("graphql-codegen-core");
|
5 | var path = require("path");
|
6 |
|
7 |
|
8 | var stripBOM = function (content) {
|
9 | content = content.toString();
|
10 |
|
11 |
|
12 |
|
13 | if (content.charCodeAt(0) === 0xfeff) {
|
14 | content = content.slice(1);
|
15 | }
|
16 | return content;
|
17 | };
|
18 | exports.parseBOM = function (content) { return JSON.parse(stripBOM(content)); };
|
19 | exports.introspectionFromFile = function (file) {
|
20 | graphql_codegen_core_1.logger.info("Loading GraphQL Introspection from file: " + file + "...");
|
21 | return new Promise(function (resolve, reject) {
|
22 | var fullPath = path.isAbsolute(file) ? file : path.resolve(process.cwd(), file);
|
23 | if (fs.existsSync(fullPath)) {
|
24 | try {
|
25 | var fileContent = fs.readFileSync(fullPath, 'utf8');
|
26 | if (!fileContent) {
|
27 | reject("Unable to read local introspection file: " + fullPath);
|
28 | }
|
29 | var introspection = exports.parseBOM(fileContent);
|
30 | if (introspection.data) {
|
31 | introspection = introspection.data;
|
32 | }
|
33 | resolve(introspection);
|
34 | }
|
35 | catch (e) {
|
36 | reject(e);
|
37 | }
|
38 | }
|
39 | else {
|
40 | reject("Unable to locate local introspection file: " + fullPath);
|
41 | }
|
42 | });
|
43 | };
|
44 |
|
\ | No newline at end of file |