-
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
Lookahead for fragments #2053
Comments
Uh oh! I think master has some improvements to lookahead, see for example #1933. (It was put on 1.9-dev, which has since been merged into master). Could you try again on master? I'm hoping to cut a new 1.9-pre version today (waiting for #2054 at least), so if you'd rather wait for a Rubygems version, it shouldn't be long! |
I just used master to test, and I get the same issue where |
Oh! sorry to hear it. What is I made a script to replicate it: # __lookahead_test.rb
$LOAD_PATH << "./lib"
require "graphql"
puts GraphQL::VERSION
class Node < GraphQL::Schema::Object
field :id, ID, null: false
end
class Query < GraphQL::Schema::Object
field :node, Node, null: true, extras: [:lookahead] do
argument :id, ID, required: true
end
def node(id:, lookahead:)
p lookahead.selections.map(&:name)
nil
end
end
class Schema < GraphQL::Schema
query(Query)
end
p Schema.execute <<-GRAPHQL
query TestQuery {
node(id: "1") {
...InjectedTestFragment
id
}
}
fragment InjectedTestFragment on Node {
__typename
}
GRAPHQL But when I run it on my local
Can you update that example to demonstrate the failure you're observing? |
Sorry for the delay in getting back to you... it turns out the issue is with Interfaces. Here's the modified script: # __lookahead_test.rb
$LOAD_PATH << "./lib"
require "graphql"
puts GraphQL::VERSION
Widget = Struct.new(:id, :name)
WIDGETS = [Widget.new("1", "foo")]
module Node
include GraphQL::Schema::Interface
field :id, ID, null: false
definition_methods do
def resolve_type(object, ctx)
WidgetType
end
end
end
class WidgetType < GraphQL::Schema::Object
implements Node
field :name, String, null: false
end
class QueryRoot < GraphQL::Schema::Object
field :widget, WidgetType, null: false
field :node, Node, null: false, extras: [:lookahead] do
argument :id, ID, required: true
end
def node(id:, lookahead:)
p lookahead.selections.map(&:name)
WIDGETS.first
end
def widget
WIDGETS.first
end
end
class Schema < GraphQL::Schema
orphan_types WidgetType
query(QueryRoot)
end
p Schema.execute <<~GRAPHQL
query {
node(id: "1") {
id
... on Widget {
name
}
}
}
GRAPHQL When this runs, we get:
So the selections on the interface itself ( |
Ohhhh thanks for figuring that out! I'll take a look early next week and follow up here. |
Feel free to give it another go on master and let me know what you think 🍻 ! |
Awesome! |
When attempting to transition from using
irep_node
to get the list of fields for a query, to usinglookahead
, this error pops up:On v1.8.13, query:
I tried returning nil like master does in lookahead.rb, but that results in no selections at all:
In irep_node, it seemed like it correctly resolved fragments, so it was straightforward to get the requested fields.
cc @swalkinshaw @dylanahsmith
The text was updated successfully, but these errors were encountered: