Skip to content

Commit 8d4b5ea

Browse files
committed
Fix tracing and objects in partials on abstract type
1 parent 067ab9c commit 8d4b5ea

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

lib/graphql/execution/next/runner.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ def begin_execute(isolated_steps, results, query, root_type, root_value)
260260
end
261261

262262
results << { "data" => data }
263-
264263
objects = [root_value]
265264
query.current_trace.objects(root_type, objects, query.context)
266265

@@ -316,6 +315,8 @@ def begin_execute(isolated_steps, results, query, root_type, root_value)
316315
if resolves_lazies
317316
resolved_type = schema.sync_lazy(resolved_type)
318317
end
318+
objects = [root_value]
319+
query.current_trace.objects(resolved_type, objects, query.context)
319320
runtime_type_at[data] = resolved_type
320321
results << { "data" => data }
321322
isolated_steps[0] << SelectionsStep.new(

spec/graphql/tracing/trace_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212

1313
describe "object hooks" do
1414
class ObjectHooksSchema < GraphQL::Schema
15-
class Thing < GraphQL::Schema::Object
15+
module Node
16+
include GraphQL::Schema::Interface
1617
field :name, String
1718
end
1819

20+
class Thing < GraphQL::Schema::Object
21+
implements Node
22+
end
23+
1924
class Query < GraphQL::Schema::Object
2025
field :things, [Thing], resolve_static: true
2126

@@ -38,6 +43,14 @@ def self.thing(context, thing:)
3843
def self.thing_name(context, thing:)
3944
thing.name
4045
end
46+
47+
field :node, Node, resolve_static: true do
48+
argument :id, ID, loads: Node, as: :node
49+
end
50+
51+
def self.node(context, node:)
52+
node
53+
end
4154
end
4255

4356
query(Query)
@@ -80,6 +93,14 @@ def object_loaded(argument_definition, object, context)
8093
res = ObjectHooksSchema.execute_next("{ thingName(thingId: \"77\") }")
8194
assert_equal "Thing #77", res["data"]["thingName"]
8295
assert_equal ["1 objects as Query", "Query.thingName.thingId loaded OpenStruct"], res.context[:log]
96+
97+
res = ObjectHooksSchema.execute_next("{ node(id: \"33\") { name } }")
98+
assert_equal "Thing #33", res["data"]["node"]["name"]
99+
assert_equal ["1 objects as Query", "Query.node.id loaded OpenStruct", "1 objects as Thing"], res.context[:log]
100+
101+
partial_res = res.query.run_partials([{ path: ["node"], object: OpenStruct.new(name: "Injected thing"), context: { log: [] } }])
102+
assert_equal "Injected thing", partial_res[0]["data"]["name"]
103+
assert_equal ["1 objects as Thing"], partial_res[0].context[:log]
83104
end
84105
end
85106
end

0 commit comments

Comments
 (0)