1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var graphql_codegen_core_1 = require("graphql-codegen-core");
|
4 | var fs = require("fs");
|
5 | var path = require("path");
|
6 | var document_finder_1 = require("../utils/document-finder");
|
7 | exports.loadFileContent = function (filePath) {
|
8 | if (fs.existsSync(filePath)) {
|
9 | var fileContent = fs.readFileSync(filePath, 'utf8');
|
10 | var fileExt = path.extname(filePath);
|
11 | if (fileExt === '.graphql' || fileExt === '.gql') {
|
12 | return graphql_codegen_core_1.parse(new graphql_codegen_core_1.Source(fileContent, filePath));
|
13 | }
|
14 | var foundDoc = document_finder_1.extractDocumentStringFromCodeFile(fileContent);
|
15 | if (foundDoc) {
|
16 | return graphql_codegen_core_1.parse(new graphql_codegen_core_1.Source(foundDoc, filePath));
|
17 | }
|
18 | else {
|
19 | return null;
|
20 | }
|
21 | }
|
22 | else {
|
23 | throw new Error("Document file " + filePath + " does not exists!");
|
24 | }
|
25 | };
|
26 | exports.loadDocumentsSources = function (filePaths) {
|
27 | return graphql_codegen_core_1.concatAST(filePaths.map(exports.loadFileContent).filter(function (content) { return content; }));
|
28 | };
|
29 |
|
\ | No newline at end of file |