UNPKG

1.39 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");
7var errors_1 = require("../../errors");
8exports.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};
27exports.loadDocumentsSources = function (filePaths) {
28 return filePaths.map(function (filePath) { return ({ filePath: filePath, content: exports.loadFileContent(filePath) }); }).filter(function (result) { return result.content; });
29};
30//# sourceMappingURL=document-loader.js.map
\No newline at end of file