1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var graphql_1 = require("graphql");
|
4 | var graphql_codegen_core_1 = require("graphql-codegen-core");
|
5 | var fs = require("fs");
|
6 | var path = require("path");
|
7 | var document_finder_1 = require("../../utils/document-finder");
|
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 Error("Document file " + filePath + " does not exists!");
|
25 | }
|
26 | };
|
27 | var effectiveRules = graphql_1.specifiedRules.filter(function (f) { return f.name !== 'NoUnusedFragments'; });
|
28 | exports.loadDocumentsSources = function (schema, filePaths) {
|
29 | var loadResults = filePaths.map(exports.loadFileContent).filter(function (content) { return content; });
|
30 | var completeAst = graphql_codegen_core_1.concatAST(loadResults);
|
31 | var errors = graphql_1.validate(schema, completeAst, effectiveRules);
|
32 | return errors.length > 0 ? errors : completeAst;
|
33 | };
|
34 |
|
\ | No newline at end of file |