UNPKG

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