@@ -45,33 +45,40 @@ export function KnownDirectives(context: ValidationContext): any {
45
45
def => def . name === node . name . value
46
46
) ;
47
47
if ( ! directiveDef ) {
48
- return new GraphQLError (
48
+ context . reportError ( new GraphQLError (
49
49
unknownDirectiveMessage ( node . name . value ) ,
50
50
[ node ]
51
- ) ;
51
+ ) ) ;
52
+ return ;
52
53
}
53
- var appliedTo = ancestors [ ancestors . length - 1 ] ;
54
- if ( appliedTo . kind === OPERATION_DEFINITION &&
55
- ! directiveDef . onOperation ) {
56
- return new GraphQLError (
57
- misplacedDirectiveMessage ( node . name . value , 'operation' ) ,
58
- [ node ]
59
- ) ;
60
- }
61
- if ( appliedTo . kind === FIELD && ! directiveDef . onField ) {
62
- return new GraphQLError (
63
- misplacedDirectiveMessage ( node . name . value , 'field' ) ,
64
- [ node ]
65
- ) ;
66
- }
67
- if ( ( appliedTo . kind === FRAGMENT_SPREAD ||
68
- appliedTo . kind === INLINE_FRAGMENT ||
69
- appliedTo . kind === FRAGMENT_DEFINITION ) &&
70
- ! directiveDef . onFragment ) {
71
- return new GraphQLError (
72
- misplacedDirectiveMessage ( node . name . value , 'fragment' ) ,
73
- [ node ]
74
- ) ;
54
+ const appliedTo = ancestors [ ancestors . length - 1 ] ;
55
+ switch ( appliedTo . kind ) {
56
+ case OPERATION_DEFINITION :
57
+ if ( ! directiveDef . onOperation ) {
58
+ context . reportError ( new GraphQLError (
59
+ misplacedDirectiveMessage ( node . name . value , 'operation' ) ,
60
+ [ node ]
61
+ ) ) ;
62
+ }
63
+ break ;
64
+ case FIELD :
65
+ if ( ! directiveDef . onField ) {
66
+ context . reportError ( new GraphQLError (
67
+ misplacedDirectiveMessage ( node . name . value , 'field' ) ,
68
+ [ node ]
69
+ ) ) ;
70
+ }
71
+ break ;
72
+ case FRAGMENT_SPREAD :
73
+ case INLINE_FRAGMENT :
74
+ case FRAGMENT_DEFINITION :
75
+ if ( ! directiveDef . onFragment ) {
76
+ context . reportError ( new GraphQLError (
77
+ misplacedDirectiveMessage ( node . name . value , 'fragment' ) ,
78
+ [ node ]
79
+ ) ) ;
80
+ }
81
+ break ;
75
82
}
76
83
}
77
84
} ;
0 commit comments