1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.validateWithCustomRules = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | const specifiedSDLRules = [
|
6 | graphql_1.LoneSchemaDefinitionRule,
|
7 | graphql_1.UniqueOperationTypesRule,
|
8 | graphql_1.UniqueTypeNamesRule,
|
9 | graphql_1.UniqueEnumValueNamesRule,
|
10 | graphql_1.UniqueFieldDefinitionNamesRule,
|
11 | graphql_1.UniqueDirectiveNamesRule,
|
12 | graphql_1.KnownTypeNamesRule,
|
13 | graphql_1.KnownDirectivesRule,
|
14 | graphql_1.UniqueDirectivesPerLocationRule,
|
15 | graphql_1.PossibleTypeExtensionsRule,
|
16 | graphql_1.UniqueArgumentNamesRule,
|
17 | graphql_1.UniqueInputFieldNamesRule,
|
18 | ];
|
19 | function validateWithCustomRules(schema, ast, customRules, isRelayCompatMode, isSchemaDocument) {
|
20 | const rules = graphql_1.specifiedRules.filter(rule => {
|
21 | if (rule === graphql_1.NoUnusedFragmentsRule || rule === graphql_1.ExecutableDefinitionsRule) {
|
22 | return false;
|
23 | }
|
24 | if (isRelayCompatMode && rule === graphql_1.KnownFragmentNamesRule) {
|
25 | return false;
|
26 | }
|
27 | return true;
|
28 | });
|
29 | if (customRules) {
|
30 | Array.prototype.push.apply(rules, customRules);
|
31 | }
|
32 | if (isSchemaDocument) {
|
33 | Array.prototype.push.apply(rules, specifiedSDLRules);
|
34 | }
|
35 | const errors = graphql_1.validate(schema, ast, rules);
|
36 | return errors.filter(error => {
|
37 | if (error.message.indexOf('Unknown directive') !== -1 && error.nodes) {
|
38 | const node = error.nodes[0];
|
39 | if (node && node.kind === graphql_1.Kind.DIRECTIVE) {
|
40 | const name = node.name.value;
|
41 | if (name === 'arguments' || name === 'argumentDefinitions') {
|
42 | return false;
|
43 | }
|
44 | }
|
45 | }
|
46 | return true;
|
47 | });
|
48 | }
|
49 | exports.validateWithCustomRules = validateWithCustomRules;
|
50 |
|
\ | No newline at end of file |