File tree 1 file changed +14
-10
lines changed
1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change 10
10
import type { ASTValidationContext } from '../ValidationContext' ;
11
11
import { GraphQLError } from '../../error/GraphQLError' ;
12
12
import { Kind } from '../../language/kinds' ;
13
- import { isExecutableDefinitionNode } from '../../language/predicates' ;
13
+ import {
14
+ isDefinitionNode ,
15
+ isExecutableDefinitionNode ,
16
+ } from '../../language/predicates' ;
14
17
import type { ASTVisitor } from '../../language/visitor' ;
15
18
16
19
export function nonExecutableDefinitionMessage ( defName : string ) : string {
@@ -27,23 +30,24 @@ export function ExecutableDefinitions(
27
30
context : ASTValidationContext ,
28
31
) : ASTVisitor {
29
32
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
+
33
40
context . reportError (
34
41
new GraphQLError (
35
42
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 ,
40
44
) ,
41
- [ definition ] ,
45
+ node ,
42
46
) ,
43
47
) ;
44
48
}
49
+ return false ;
45
50
}
46
- return false ;
47
51
} ,
48
52
} ;
49
53
}
You can’t perform that action at this time.
0 commit comments