Skip to content

Commit d2cec71

Browse files
committed
ActiveSupport::Notifications: fix fiber resume without previous event
1 parent f14562c commit d2cec71

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/graphql/tracing/notifications_trace.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def dataloader_fiber_yield(source)
137137

138138
def dataloader_fiber_resume(source)
139139
prev_ev = Fiber[PREVIOUS_EV_KEY]
140-
begin_notifications_event(prev_ev.name, prev_ev.payload)
140+
if prev_ev
141+
begin_notifications_event(prev_ev.name, prev_ev.payload)
142+
end
141143
super
142144
end
143145

spec/graphql/tracing/active_support_notifications_trace_spec.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,27 @@ class Thing < GraphQL::Schema::Object
2323
end
2424

2525
class Query < GraphQL::Schema::Object
26-
field :nameable, Nameable
26+
field :nameable, Nameable do
27+
argument :id, ID, loads: Thing, as: :thing
28+
end
2729

28-
def nameable
29-
dataload(ThingSource, 1)
30+
def nameable(thing:)
31+
thing
3032
end
3133
end
3234

3335
query(Query)
3436
trace_with GraphQL::Tracing::ActiveSupportNotificationsTrace
3537
use GraphQL::Dataloader
3638
orphan_types(Thing)
39+
40+
def self.object_from_id(id, ctx)
41+
ctx.dataloader.with(ThingSource).load(id)
42+
end
43+
44+
def self.resolve_type(_abs, _obj, _ctx)
45+
Thing
46+
end
3747
end
3848

3949
it "emits tracing info" do
@@ -42,7 +52,7 @@ def nameable
4252
events << [name, payload]
4353
}
4454
ActiveSupport::Notifications.subscribed(callback) do
45-
AsnSchema.execute("{ nameable { name } }")
55+
AsnSchema.execute("{ nameable(id: 1) { name } }")
4656
end
4757

4858
expected_names = [
@@ -51,7 +61,6 @@ def nameable
5161
"validate.graphql",
5262
"analyze.graphql",
5363
"authorized.graphql",
54-
"execute_field.graphql",
5564
"dataloader_source.graphql",
5665
"execute_field.graphql",
5766
"resolve_type.graphql",

0 commit comments

Comments
 (0)