UNPKG

1.23 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var graphql_codegen_core_1 = require("graphql-codegen-core");
4var fs = require("fs");
5var path = require("path");
6var document_finder_1 = require("../utils/document-finder");
7exports.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};
26exports.loadDocumentsSources = function (filePaths) {
27 return graphql_codegen_core_1.concatAST(filePaths.map(exports.loadFileContent).filter(function (content) { return content; }));
28};
29//# sourceMappingURL=document-loader.js.map
\No newline at end of file