Skip to content

Commit 761191d

Browse files
authored
Merge pull request #5070 from rmosolgo/asn-super-fix
Call super in NotificationsTrace
2 parents 951cb16 + e480c70 commit 761191d

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

lib/graphql/tracing/notifications_trace.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def initialize(engine:, **rest)
3333
"resolve_type_lazy" => "resolve_type.graphql",
3434
}.each do |trace_method, platform_key|
3535
module_eval <<-RUBY, __FILE__, __LINE__
36-
def #{trace_method}(**metadata, &blk)
37-
@notifications_engine.instrument("#{platform_key}", metadata, &blk)
36+
def #{trace_method}(**metadata, &block)
37+
@notifications_engine.instrument("#{platform_key}", metadata) { super(**metadata, &block) }
3838
end
3939
RUBY
4040
end

spec/graphql/tracing/notifications_trace_spec.rb

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,40 @@ def int
1212
end
1313
end
1414

15+
class DummyEngine
16+
def self.dispatched_events
17+
@dispatched_events ||= []
18+
end
19+
20+
def self.instrument(event, payload)
21+
dispatched_events << [event, payload]
22+
yield if block_given?
23+
end
24+
end
25+
26+
module OtherTrace
27+
def execute_query(query:)
28+
query.context[:other_trace_ran] = true
29+
super
30+
end
31+
end
32+
1533
class Schema < GraphQL::Schema
1634
query Query
35+
trace_with OtherTrace
36+
trace_with GraphQL::Tracing::NotificationsTrace, engine: DummyEngine
1737
end
1838
end
1939

20-
describe "Observing" do
21-
it "dispatches the event to the notifications engine with suffixed key" do
22-
dispatched_events = trigger_fake_notifications_tracer(NotificationsTraceTest::Schema).to_h
40+
before do
41+
NotificationsTraceTest::DummyEngine.dispatched_events.clear
42+
end
2343

24-
assert dispatched_events.length > 0
2544

45+
describe "Observing" do
46+
it "dispatches the event to the notifications engine with suffixed key" do
47+
NotificationsTraceTest::Schema.execute "query X { int }"
48+
dispatched_events = NotificationsTraceTest::DummyEngine.dispatched_events.to_h
2649
expected_event_keys = [
2750
'execute_multiplex.graphql',
2851
'analyze_multiplex.graphql',
@@ -43,20 +66,10 @@ class Schema < GraphQL::Schema
4366
assert payload.is_a?(Hash)
4467
end
4568
end
46-
end
47-
48-
def trigger_fake_notifications_tracer(schema)
49-
dispatched_events = []
50-
engine = Object.new
5169

52-
engine.define_singleton_method(:instrument) do |event, payload, &blk|
53-
dispatched_events << [event, payload]
54-
blk.call if blk
70+
it "works with other tracers" do
71+
res = NotificationsTraceTest::Schema.execute "query X { int }"
72+
assert res.context[:other_trace_ran]
5573
end
56-
57-
schema.trace_with GraphQL::Tracing::NotificationsTrace, engine: engine
58-
schema.execute "query X { int }"
59-
60-
dispatched_events
6174
end
6275
end

0 commit comments

Comments
 (0)