-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 GraphQL::Execution::Lookahead#selections #1907
Conversation
79026bd
to
48f3e8f
Compare
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.
👏 ! Thanks for taking this on! I added a couple comments about how it could be made more consistent, let me know what you think.
@rmosolgo addressed your comments, should be good now once CI passes. Thanks for the help! |
Cool, thanks for taking a look! What do you think of my suggestion in 8bb135c ? Effectively, it merges selections, so that a { b }
a { c } Is treated the same as a { b c } The GraphQL runtime does this, too -- |
Ahhh ok. What is the reasoning for only returning it once? I would think that they are different selections because they have different sub-selections, This could potentially cause issues when attempting to dig deeped into the sub-lookaheads. ie.
|
I'm sorry, I don't quite see it. Could you help me understand what scenario you want the different AST nodes reflected in a lookahead? Like, when would you interact with a # snippet 1, the client has requested data in two different selections,
# even though they're merged during query execution
query {
users { totalCount }
users { name }
end # Snippet 2, `totalCount` and `name` are part of the same selection
query {
users {
totalCount
name
}
} What I've done in 8bb135c is normalized in that case, so regardless of whether the client sends snippet 1 or snippet 2, it looks the same: users_field = lookahead.selection("users")
p users_field.selections.map(&:name)
# [:total_count, :name] ☝️ consider that bit of Ruby code, perhaps inside a resolver. If |
This makes sense now, and is a much better way of dealing with the problem. Essentially, we can consider 'name' to be unique? |
👌 Bingo! Ok, caveat: there are still unhandled edge cases here with aliases. For example, I'm not really sure what this will return: query {
users {
totalCount
name
alsoName: name
}
} Because |
This PR adds the ability to get all of the selections from a Lookahead. I decided to keep the implementation simple by just re-using the
selection
method instead of refactoring, let me know if that's alright 😄Continuation of #1894