1 | "use strict";
|
2 | var graphql_1 = require("graphql");
|
3 | var fs = require("fs");
|
4 | var path = require("path");
|
5 | var document_finder_1 = require("./document-finder");
|
6 | exports.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 | };
|
25 | exports.loadDocumentsSources = function (filePaths) {
|
26 | return graphql_1.concatAST(filePaths.map(exports.loadFileContent).filter(function (content) { return content; }));
|
27 | };
|
28 |
|
\ | No newline at end of file |