Skip to content

Commit 71759eb

Browse files
committed
Remove definition iteration from 'ExecutableDefinitions' rule
1 parent 7cfd686 commit 71759eb

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/validation/rules/ExecutableDefinitions.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import type { ASTValidationContext } from '../ValidationContext';
1111
import { GraphQLError } from '../../error/GraphQLError';
1212
import { Kind } from '../../language/kinds';
13-
import { isExecutableDefinitionNode } from '../../language/predicates';
13+
import {
14+
isDefinitionNode,
15+
isExecutableDefinitionNode,
16+
} from '../../language/predicates';
17+
import type { ASTNode } from '../../language/ast';
1418
import type { ASTVisitor } from '../../language/visitor';
1519

1620
export function nonExecutableDefinitionMessage(defName: string): string {
@@ -27,23 +31,26 @@ export function ExecutableDefinitions(
2731
context: ASTValidationContext,
2832
): ASTVisitor {
2933
return {
30-
Document(node) {
31-
for (const definition of node.definitions) {
32-
if (!isExecutableDefinitionNode(definition)) {
34+
enter(node) {
35+
if (isDefinitionNode(node)) {
36+
if (!isExecutableDefinitionNode(node)) {
3337
context.reportError(
3438
new GraphQLError(
3539
nonExecutableDefinitionMessage(
36-
definition.kind === Kind.SCHEMA_DEFINITION ||
37-
definition.kind === Kind.SCHEMA_EXTENSION
38-
? 'schema'
39-
: definition.name.value,
40+
isSchemaNode(node) ? 'schema' : node.name.value,
4041
),
41-
[definition],
42+
node,
4243
),
4344
);
4445
}
46+
return false;
4547
}
46-
return false;
4748
},
4849
};
4950
}
51+
52+
function isSchemaNode(node: ASTNode): boolean %checks {
53+
return (
54+
node.kind === Kind.SCHEMA_DEFINITION || node.kind === Kind.SCHEMA_EXTENSION
55+
);
56+
}

0 commit comments

Comments
 (0)