UNPKG

1.76 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var graphql_1 = require("graphql");
4var errors_1 = require("../../errors");
5var rulesToIgnore = ['KnownFragmentNames', 'NoUnusedFragments', 'NoUnusedVariables', 'KnownDirectives'];
6var effectiveRules = graphql_1.specifiedRules.filter(function (f) { return !rulesToIgnore.includes(f.name); });
7exports.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};
15function 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}
30exports.checkValidationErrors = checkValidationErrors;
31//# sourceMappingURL=validate-documents.js.map
\No newline at end of file