Skip to content

Commit a5688e2

Browse files
author
Robert Mosolgo
authored
Merge pull request #3494 from rmosolgo/write-response-on-the-way
Build up the response while executing the query
2 parents cd337dc + 61b29d8 commit a5688e2

File tree

6 files changed

+181
-213
lines changed

6 files changed

+181
-213
lines changed

lib/graphql/backtrace/table.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def build_rows(context_entry, rows:, top: false)
8383
value = if top && @override_value
8484
@override_value
8585
else
86-
@context.query.context.namespace(:interpreter)[:runtime].value_at(context_entry.path)
86+
value_at(@context.query.context.namespace(:interpreter)[:runtime], context_entry.path)
8787
end
8888
rows << [
8989
"#{context_entry.ast_node ? context_entry.ast_node.position.join(":") : ""}",
@@ -130,7 +130,7 @@ def build_rows(context_entry, rows:, top: false)
130130
if object.is_a?(GraphQL::Schema::Object)
131131
object = object.object
132132
end
133-
value = context_entry.namespace(:interpreter)[:runtime].value_at([])
133+
value = value_at(context_entry.namespace(:interpreter)[:runtime], [])
134134
rows << [
135135
"#{position}",
136136
"#{op_type}#{op_name ? " #{op_name}" : ""}",
@@ -142,6 +142,18 @@ def build_rows(context_entry, rows:, top: false)
142142
raise "Unexpected get_rows subject #{context_entry.class} (#{context_entry.inspect})"
143143
end
144144
end
145+
146+
def value_at(runtime, path)
147+
response = runtime.response
148+
path.each do |key|
149+
if response && (response = response[key])
150+
next
151+
else
152+
break
153+
end
154+
end
155+
response
156+
end
145157
end
146158
end
147159
end

lib/graphql/execution/execute.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Execution
66
class Execute
77

88
# @api private
9-
class Skip; end
9+
class Skip < GraphQL::Error; end
1010

1111
# Just a singleton for implementing {Query::Context#skip}
1212
# @api private

lib/graphql/execution/interpreter.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require "graphql/execution/interpreter/arguments"
55
require "graphql/execution/interpreter/arguments_cache"
66
require "graphql/execution/interpreter/execution_errors"
7-
require "graphql/execution/interpreter/hash_response"
87
require "graphql/execution/interpreter/runtime"
98
require "graphql/execution/interpreter/resolve"
109
require "graphql/execution/interpreter/handles_raw_value"
@@ -19,7 +18,7 @@ def initialize
1918
def execute(_operation, _root_type, query)
2019
runtime = evaluate(query)
2120
sync_lazies(query: query)
22-
runtime.final_value
21+
runtime.response
2322
end
2423

2524
def self.use(schema_class)
@@ -57,7 +56,7 @@ def self.finish_multiplex(_results, multiplex)
5756

5857
def self.finish_query(query, _multiplex)
5958
{
60-
"data" => query.context.namespace(:interpreter)[:runtime].final_value
59+
"data" => query.context.namespace(:interpreter)[:runtime].response
6160
}
6261
end
6362

@@ -67,10 +66,7 @@ def evaluate(query)
6766
# Although queries in a multiplex _share_ an Interpreter instance,
6867
# they also have another item of state, which is private to that query
6968
# in particular, assign it here:
70-
runtime = Runtime.new(
71-
query: query,
72-
response: HashResponse.new,
73-
)
69+
runtime = Runtime.new(query: query)
7470
query.context.namespace(:interpreter)[:runtime] = runtime
7571

7672
query.trace("execute_query", {query: query}) do
@@ -91,7 +87,7 @@ def sync_lazies(query: nil, multiplex: nil)
9187
final_values = queries.map do |query|
9288
runtime = query.context.namespace(:interpreter)[:runtime]
9389
# it might not be present if the query has an error
94-
runtime ? runtime.final_value : nil
90+
runtime ? runtime.response : nil
9591
end
9692
final_values.compact!
9793
tracer.trace("execute_query_lazy", {multiplex: multiplex, query: query}) do

lib/graphql/execution/interpreter/hash_response.rb

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)