Skip to content

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

Conversation

IvanGoncharov
Copy link
Member

No description provided.

@@ -27,23 +30,24 @@ export function ExecutableDefinitions(
context: ASTValidationContext,
): ASTVisitor {
return {
Document(node) {
for (const definition of node.definitions) {
if (!isExecutableDefinitionNode(definition)) {
Copy link
Member Author

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 😄

@IvanGoncharov IvanGoncharov force-pushed the simplifyExecutableDefinitionsRule branch from f402403 to 71759eb Compare August 13, 2018 14:47
for (const definition of node.definitions) {
if (!isExecutableDefinitionNode(definition)) {
enter(node) {
if (isDefinitionNode(node)) {
Copy link
Contributor

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)) {

Copy link
Member Author

@IvanGoncharov IvanGoncharov Aug 20, 2018

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.

Copy link
Contributor

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

Copy link
Contributor

@mjmahone mjmahone left a 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)) {
Copy link
Contributor

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

Base automatically changed from master to main January 27, 2021 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants