diff --git a/lib/graphql/execution/interpreter/runtime.rb b/lib/graphql/execution/interpreter/runtime.rb index db03aded2a..8b68a1aff3 100644 --- a/lib/graphql/execution/interpreter/runtime.rb +++ b/lib/graphql/execution/interpreter/runtime.rb @@ -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 @@ -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) diff --git a/spec/graphql/execution/lookahead_spec.rb b/spec/graphql/execution/lookahead_spec.rb index 9b44e52367..d718e24079 100644 --- a/spec/graphql/execution/lookahead_spec.rb +++ b/spec/graphql/execution/lookahead_spec.rb @@ -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