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 | var errors_1 = require("../../errors");
|
8 | exports.loadFileContent = function (filePath) {
|
9 | if (fs.existsSync(filePath)) {
|
10 | var fileContent = fs.readFileSync(filePath, 'utf8');
|
11 | var fileExt = path.extname(filePath);
|
12 | if (fileExt === '.graphql' || fileExt === '.gql') {
|
13 | return graphql_codegen_core_1.parse(new graphql_codegen_core_1.Source(fileContent, filePath));
|
14 | }
|
15 | var foundDoc = document_finder_1.extractDocumentStringFromCodeFile(fileContent);
|
16 | if (foundDoc) {
|
17 | return graphql_codegen_core_1.parse(new graphql_codegen_core_1.Source(foundDoc, filePath));
|
18 | }
|
19 | else {
|
20 | return null;
|
21 | }
|
22 | }
|
23 | else {
|
24 | throw new errors_1.DetailedError("\n\n Failed to load a document.\n Document file " + filePath + " does not exists.\n\n ");
|
25 | }
|
26 | };
|
27 | exports.loadDocumentsSources = function (filePaths) {
|
28 | return filePaths.map(function (filePath) { return ({ filePath: filePath, content: exports.loadFileContent(filePath) }); }).filter(function (result) { return result.content; });
|
29 | };
|
30 |
|
\ | No newline at end of file |