File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,10 @@ import type { OperationDefinitionNode } from '../../language/ast';
6
6
import type { ASTValidationContext } from '../ValidationContext' ;
7
7
8
8
/**
9
- * Subscriptions must only include one field.
9
+ * Subscriptions must only include a non-introspection field.
10
10
*
11
- * A GraphQL subscription is valid only if it contains a single root field.
11
+ * A GraphQL subscription is valid only if it contains a single root field and
12
+ * that root field is not an introspection field.
12
13
*/
13
14
export function SingleFieldSubscriptionsRule (
14
15
context : ASTValidationContext ,
@@ -25,6 +26,20 @@ export function SingleFieldSubscriptionsRule(
25
26
node . selectionSet . selections . slice ( 1 ) ,
26
27
) ,
27
28
) ;
29
+ } else {
30
+ const selection = node . selectionSet . selections [ 0 ] ;
31
+ const fieldName = selection [ 0 ] . name . value ;
32
+ // fieldName represents an introspection field if it starts with `__`
33
+ if ( fieldName [ 0 ] === '_' && fieldName [ 1 ] === '_' ) {
34
+ context . reportError (
35
+ new GraphQLError (
36
+ node . name
37
+ ? `Subscription "${ node . name . value } " must not select an introspection top level field.`
38
+ : 'Anonymous Subscription must not select an introspection top level field.' ,
39
+ node . selectionSet . selections ,
40
+ ) ,
41
+ ) ;
42
+ }
28
43
}
29
44
}
30
45
} ,
You can’t perform that action at this time.
0 commit comments