1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var graphql_1 = require("graphql");
|
4 | var errors_1 = require("../../errors");
|
5 | var rulesToIgnore = ['KnownFragmentNames', 'NoUnusedFragments', 'NoUnusedVariables', 'KnownDirectives'];
|
6 | var effectiveRules = graphql_1.specifiedRules.filter(function (f) { return !rulesToIgnore.includes(f.name); });
|
7 | exports.validateGraphQlDocuments = function (schema, documentFiles) {
|
8 | return documentFiles
|
9 | .map(function (result) { return ({
|
10 | filePath: result.filePath,
|
11 | errors: graphql_1.validate(schema, result.content, effectiveRules)
|
12 | }); })
|
13 | .filter(function (r) { return r.errors.length > 0; });
|
14 | };
|
15 | function checkValidationErrors(loadDocumentErrors) {
|
16 | if (loadDocumentErrors.length > 0) {
|
17 | var errors = [];
|
18 | var errorCount = 0;
|
19 | for (var _i = 0, loadDocumentErrors_1 = loadDocumentErrors; _i < loadDocumentErrors_1.length; _i++) {
|
20 | var loadDocumentError = loadDocumentErrors_1[_i];
|
21 | for (var _a = 0, _b = loadDocumentError.errors; _a < _b.length; _a++) {
|
22 | var graphQLError = _b[_a];
|
23 | errors.push("\n " + loadDocumentError.filePath + ": \n " + graphQLError.message + "\n ");
|
24 | errorCount++;
|
25 | }
|
26 | }
|
27 | throw new errors_1.DetailedError("Found " + errorCount + " errors in your documents", "\n Found " + errorCount + " errors.\n GraphQL Code Generator validated your GraphQL documents against the schema.\n Please fix following errors and run codegen again:\n " + errors.join('') + "\n\n ");
|
28 | }
|
29 | }
|
30 | exports.checkValidationErrors = checkValidationErrors;
|
31 |
|
\ | No newline at end of file |