Skip to content

Commit f402403

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

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/validation/rules/ExecutableDefinitions.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
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';
1417
import type { ASTVisitor } from '../../language/visitor';
1518

1619
export function nonExecutableDefinitionMessage(defName: string): string {
@@ -27,23 +30,24 @@ export function ExecutableDefinitions(
2730
context: ASTValidationContext,
2831
): ASTVisitor {
2932
return {
30-
Document(node) {
31-
for (const definition of node.definitions) {
32-
if (!isExecutableDefinitionNode(definition)) {
33+
enter(node) {
34+
if (isDefinitionNode(node)) {
35+
if (!isExecutableDefinitionNode(node)) {
36+
const isSchemaNode =
37+
node.kind === Kind.SCHEMA_DEFINITION ||
38+
node.kind === Kind.SCHEMA_EXTENSION;
39+
3340
context.reportError(
3441
new GraphQLError(
3542
nonExecutableDefinitionMessage(
36-
definition.kind === Kind.SCHEMA_DEFINITION ||
37-
definition.kind === Kind.SCHEMA_EXTENSION
38-
? 'schema'
39-
: definition.name.value,
43+
isSchemaNode ? 'schema' : node.name.value,
4044
),
41-
[definition],
45+
node,
4246
),
4347
);
4448
}
49+
return false;
4550
}
46-
return false;
4751
},
4852
};
4953
}

0 commit comments

Comments
 (0)