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 a basic lookahead object #1894

Merged
merged 4 commits into from
Oct 11, 2018
Merged

Add a basic lookahead object #1894

merged 4 commits into from
Oct 11, 2018

Conversation

rmosolgo
Copy link
Owner

@rmosolgo rmosolgo commented Oct 9, 2018

I'm trying to migrate from irep_node:-based lookahead, so I want to implement something that will work with the current execution code and with the future execution code, i think this will work.

@rmosolgo rmosolgo added this to the 1.8.11 milestone Oct 9, 2018
@rmosolgo
Copy link
Owner Author

Oops, this won't work in cases like

{
  f1 { a } 
  f1 { b } 
}

because it only keeps the first AST node matching a selection. So selection("f1").selection("b").selected? will be false, when it should be true.

Just like execution, it should keep a list of AST nodes, not just 1.

@rmosolgo
Copy link
Owner Author

This still doesn't work great with Unions, I mean, fields that return unions won't play nice with lookahead yet.

@rmosolgo
Copy link
Owner Author

I documented that shortcoming, we can cross that bridge when we get there.

@rmosolgo rmosolgo merged commit de7f5b0 into master Oct 11, 2018
@rmosolgo rmosolgo deleted the lookahead branch October 11, 2018 17:23
@ianks
Copy link
Contributor

ianks commented Oct 17, 2018

@rmosolgo is it possible to get all selected fields with this API?

@rmosolgo
Copy link
Owner Author

Not yet, I put it off because I didn't need it yet. I think a nice API would be to add #selections which returns a list of Lookaheads for each selection, and then make each Lookahead respond to #name, so that you can tell what it represents.

next_lookaheads = lookahead.selections  
# => [#<GraphQL::Execution::Lookahead ...>, ...]
next_lookaheads.map(&:name) 
# => ["next", "field", "names", "go", "here"]

What do you think? Want to take a crack at it?

@rmosolgo rmosolgo mentioned this pull request Oct 19, 2018
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants