Class: GraphQL::Subscriptions::Instrumentation::SubscriptionRegistrationResolve

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/subscriptions/instrumentation.rb

Instance Method Summary collapse

Constructor Details

#initialize(inner_proc) ⇒ SubscriptionRegistrationResolve

Returns a new instance of SubscriptionRegistrationResolve.



41
42
43
# File 'lib/graphql/subscriptions/instrumentation.rb', line 41

def initialize(inner_proc)
  @inner_proc = inner_proc
end

Instance Method Details

#call(obj, args, ctx) ⇒ Object

Wrap the proc with subscription registration logic



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/graphql/subscriptions/instrumentation.rb', line 46

def call(obj, args, ctx)
  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,
    )
    ctx.skip
  elsif ctx.irep_node.subscription_topic == ctx.query.subscription_topic
    # The root object is _already_ the subscription update:
    @inner_proc.call(obj, args, ctx)
  else
    # This is a subscription update, but this event wasn't triggered.
    ctx.skip
  end
end