-
Notifications
You must be signed in to change notification settings - Fork 2k
Remove definition iteration from 'ExecutableDefinitions' rule #1466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove definition iteration from 'ExecutableDefinitions' rule #1466
Conversation
@@ -27,23 +30,24 @@ export function ExecutableDefinitions( | |||
context: ASTValidationContext, | |||
): ASTVisitor { | |||
return { | |||
Document(node) { | |||
for (const definition of node.definitions) { | |||
if (!isExecutableDefinitionNode(definition)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjmahone I was searching for non-SDL examples of iterating over all definition pattern and found this 😄
f402403
to
71759eb
Compare
for (const definition of node.definitions) { | ||
if (!isExecutableDefinitionNode(definition)) { | ||
enter(node) { | ||
if (isDefinitionNode(node)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can combine these into a single if statement:
if (isDefinitionNode(node) && !isExecutableDefinitionNode(node)) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually no, since you need to return false if isDefinitionNode
is true to skip other definitions.
But I starting to think this solution is too complicated and we need to find a generic one for all similar cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you're right, I missed the return false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is too complex as-is. And I wouldn't want to block this clean up on figuring out how to abstract this idea.
I do think we should provide an "enum type" for the return values of the ASTVisitor
, like
const STOP_TRAVERSAL = false;
...
type VISITOR_RETURN_VALUEs =
| STOP_TRAVERSAL
| ...;
But that's mostly unrelated to this.
for (const definition of node.definitions) { | ||
if (!isExecutableDefinitionNode(definition)) { | ||
enter(node) { | ||
if (isDefinitionNode(node)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you're right, I missed the return false
No description provided.