Skip to content
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

Add an @take(n: Int!) directive #316

Open
u9g opened this issue Jun 15, 2023 · 1 comment
Open

Add an @take(n: Int!) directive #316

u9g opened this issue Jun 15, 2023 · 1 comment
Labels
A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality

Comments

@u9g
Copy link
Contributor

u9g commented Jun 15, 2023

This would allow for only taking the first entry in an iterator, or only taking two, or whatever. This is already possible at the root vertex because you decide how many you want to take from the iterator for execute_query but having something like this in trustfall would enable not consuming an entire iterator of an edge or list.

A recent example would be a linter:

query {
  Run {
    ... on NewExpression {
      arguments @take(n: 1) {
        
      }
    }
  }
}

Where I only needed the first argument of the arguments iterator.

Alternatives: The best you can hope for is to subclass your iterator to a new edge that has a take edge with edge properties for how many to take, This makes the query and schema much more confusing for not much reason if this can be implemented natively. Example:

query {
  Run {
    ... on NewExpression {
      arguments {
        Take(n: 1) {
          iter {
            
          }
        }
      }
    }
  }
}
@obi1kenobi obi1kenobi changed the title Add an @take(n: Int!) annotation Add an @take(n: Int!) directive Jun 15, 2023
@obi1kenobi
Copy link
Owner

obi1kenobi commented Jun 15, 2023

Good idea. We should probably do this.

Regarding the workaround, we can do slightly better: the take argument can be inlined into the parent edge itself instead of being on yet another edge.

query {
  Run {
    ... on NewExpression {
      arguments(take: 1) {
        # ...
      }
    }
  }
}

@settings settings bot removed the enhancement label Jun 30, 2023
@obi1kenobi obi1kenobi added A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality labels Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntax Area: query or schema syntax C-feature-request Category: request for new future functionality
Projects
None yet
Development

No branches or pull requests

2 participants