Skip to content

Commit

Permalink
Use else branch to report second error
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Nov 25, 2020
1 parent 5b39acd commit 15eded0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/validation/rules/SingleFieldSubscriptionsRule.js
Expand Up @@ -26,6 +26,20 @@ export function SingleFieldSubscriptionsRule(
node.selectionSet.selections.slice(1),
),
);
} else {
const selection = node.selectionSet.selections[0];
const fieldName = selection.name.value;
// fieldName represents an introspection field if it starts with `__`
if (fieldName[0] === '_' && fieldName[1] === '_') {
context.reportError(
new GraphQLError(
node.name
? `Subscription "${node.name.value}" must not select an introspection top level field.`
: 'Anonymous Subscription must not select an introspection top level field.',
node.selectionSet.selections,
),
);
}
}
const selection = node.selectionSet.selections[0];
const fieldName = selection.name.value;
Expand Down

0 comments on commit 15eded0

Please sign in to comment.