File tree 1 file changed +17
-10
lines changed 1 file changed +17
-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' ;
17
+ import type { ASTNode } from '../../language/ast' ;
14
18
import type { ASTVisitor } from '../../language/visitor' ;
15
19
16
20
export function nonExecutableDefinitionMessage ( defName : string ) : string {
@@ -27,23 +31,26 @@ export function ExecutableDefinitions(
27
31
context : ASTValidationContext ,
28
32
) : ASTVisitor {
29
33
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 ) ) {
33
37
context . reportError (
34
38
new GraphQLError (
35
39
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 ,
40
41
) ,
41
- [ definition ] ,
42
+ node ,
42
43
) ,
43
44
) ;
44
45
}
46
+ return false ;
45
47
}
46
- return false ;
47
48
} ,
48
49
} ;
49
50
}
51
+
52
+ function isSchemaNode ( node : ASTNode ) : boolean % checks {
53
+ return (
54
+ node . kind === Kind . SCHEMA_DEFINITION || node . kind === Kind . SCHEMA_EXTENSION
55
+ ) ;
56
+ }
You can’t perform that action at this time.
0 commit comments