Skip to content

Commit 5fb316d

Browse files
committed
Add test for trace inheritance bug
1 parent 9e6dcd8 commit 5fb316d

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

spec/graphql/tracing/legacy_trace_spec.rb

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
custom_tracer = Module.new do
77
def self.trace(key, data)
88
if key == "execute_query"
9-
data[:query].context[:trace_ran] = true
9+
data[:query].context[:tracer_ran] = true
1010
end
1111
yield
1212
end
@@ -29,9 +29,53 @@ def int
2929

3030

3131
res1 = parent_schema.execute("{ int }")
32-
assert_equal true, res1.context[:trace_ran]
32+
assert_equal true, res1.context[:tracer_ran]
3333

3434
res2 = child_schema.execute("{ int }")
35-
assert_equal true, res2.context[:trace_ran]
35+
assert_equal true, res2.context[:tracer_ran]
36+
end
37+
38+
it "Works with new trace modules in the parent class" do
39+
custom_tracer = Module.new do
40+
def self.trace(key, data)
41+
if key == "execute_query"
42+
data[:query].context[:tracer_ran] = true
43+
end
44+
yield
45+
end
46+
end
47+
48+
custom_trace_module = Module.new do
49+
def execute_query(query:)
50+
query.context[:trace_module_ran] = true
51+
end
52+
end
53+
54+
55+
query_type = Class.new(GraphQL::Schema::Object) do
56+
graphql_name("Query")
57+
field :int, Integer
58+
def int
59+
4
60+
end
61+
end
62+
63+
parent_schema = Class.new(GraphQL::Schema) do
64+
query(query_type)
65+
trace_with(custom_trace_module)
66+
end
67+
68+
child_schema = Class.new(parent_schema) do
69+
tracer(custom_tracer)
70+
end
71+
72+
73+
res1 = parent_schema.execute("{ int }")
74+
assert_equal true, res1.context[:trace_module_ran]
75+
assert_nil res1.context[:tracer_ran]
76+
77+
res2 = child_schema.execute("{ int }")
78+
assert_equal true, res2.context[:trace_module_ran]
79+
assert_equal true, res1.context[:tracer_ran]
3680
end
3781
end

0 commit comments

Comments
 (0)