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

Support lookahead in interpreter #1976

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/graphql/execution/interpreter/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def gather_selections(owner_type, selections, selections_by_name)
def evaluate_selections(path, owner_object, owner_type, selections, root_operation_type: nil)
selections_by_name = {}
gather_selections(owner_type, selections, selections_by_name)
selections_by_name.each do |result_name, fields|
ast_node = fields.first
selections_by_name.each do |result_name, field_ast_nodes|
ast_node = field_ast_nodes.first
field_name = ast_node.name
field_defn = owner_type.get_field(field_name)
is_introspection = false
Expand Down Expand Up @@ -136,12 +136,18 @@ def evaluate_selections(path, owner_object, owner_type, selections, root_operati
kwarg_arguments[:execution_errors] = ExecutionErrors.new(context, ast_node, next_path)
when :path
kwarg_arguments[:path] = next_path
when :lookahead
kwarg_arguments[:lookahead] = Execution::Lookahead.new(
query: query,
ast_nodes: field_ast_nodes,
field: field_defn,
)
else
kwarg_arguments[extra] = field_defn.fetch_extra(extra, context)
end
end

next_selections = fields.inject([]) { |memo, f| memo.concat(f.selections) }
next_selections = field_ast_nodes.inject([]) { |memo, f| memo.concat(f.selections) }

app_result = query.trace("execute_field", {field: field_defn, path: next_path}) do
field_defn.resolve(object, kwarg_arguments, context)
Expand Down
3 changes: 3 additions & 0 deletions spec/graphql/execution/lookahead_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def self.after_query(q)
class Schema < GraphQL::Schema
query(Query)
instrument :query, LookaheadInstrumenter
if TESTING_INTERPRETER
use GraphQL::Execution::Interpreter
end
end
end

Expand Down