Skip to content

Commit 15eded0

Browse files
committed
Use else branch to report second error
1 parent 5b39acd commit 15eded0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/validation/rules/SingleFieldSubscriptionsRule.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ export function SingleFieldSubscriptionsRule(
2626
node.selectionSet.selections.slice(1),
2727
),
2828
);
29+
} else {
30+
const selection = node.selectionSet.selections[0];
31+
const fieldName = selection.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+
}
2943
}
3044
const selection = node.selectionSet.selections[0];
3145
const fieldName = selection.name.value;

0 commit comments

Comments
 (0)