class GraphQL::Subscriptions::Instrumentation

Wrap the root fields of the subscription type with special logic for:

Public Class Methods

new(schema:) click to toggle source
# File lib/graphql/subscriptions/instrumentation.rb, line 8
def initialize(schema:)
  @schema = schema
end

Public Instance Methods

after_query(query) click to toggle source

After checking the root fields, pass the gathered events to the store

# File lib/graphql/subscriptions/instrumentation.rb, line 20
def after_query(query)
  events = query.context.namespace(:subscriptions)[:events]
  if events && events.any?
    @schema.subscriptions.write_subscription(query, events)
  end
end
before_query(query) click to toggle source

If needed, prepare to gather events which this query subscribes to

# File lib/graphql/subscriptions/instrumentation.rb, line 13
def before_query(query)
  if query.subscription? && !query.subscription_update?
    query.context.namespace(:subscriptions)[:events] = []
  end
end