Class: GraphQL::Subscriptions::Instrumentation::SubscriptionRegistrationResolve
- Inherits:
-
Object
- Object
- GraphQL::Subscriptions::Instrumentation::SubscriptionRegistrationResolve
- Defined in:
- lib/graphql/subscriptions/instrumentation.rb
Instance Method Summary collapse
-
#call(obj, args, ctx) ⇒ Object
Wrap the proc with subscription registration logic.
-
#initialize(inner_proc) ⇒ SubscriptionRegistrationResolve
constructor
A new instance of SubscriptionRegistrationResolve.
Constructor Details
#initialize(inner_proc) ⇒ SubscriptionRegistrationResolve
Returns a new instance of SubscriptionRegistrationResolve.
40 41 42 |
# File 'lib/graphql/subscriptions/instrumentation.rb', line 40 def initialize(inner_proc) @inner_proc = inner_proc end |
Instance Method Details
#call(obj, args, ctx) ⇒ Object
Wrap the proc with subscription registration logic
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/graphql/subscriptions/instrumentation.rb', line 45 def call(obj, args, ctx) result = nil if @inner_proc && !@inner_proc.is_a?(GraphQL::Field::Resolve::BuiltInResolve) result = @inner_proc.call(obj, args, ctx) end events = ctx.namespace(:subscriptions)[:events] if events # This is the first execution, so gather an Event # for the backend to register: events << Subscriptions::Event.new( name: ctx.field.name, arguments: args, context: ctx, ) result elsif ctx.irep_node.subscription_topic == ctx.query.subscription_topic if !result.nil? result elsif obj.is_a?(GraphQL::Schema::Object) # The root object is _already_ the subscription update: obj.object else obj end else # This is a subscription update, but this event wasn't triggered. ctx.skip end end |