class GraphQL::Subscriptions::Instrumentation

  • Evaluating the triggered portion(s) of the subscription during later execution
    - Registering the subscription during the first execution
    Wrap the root fields of the subscription type with special logic for:

def after_query(query)

After checking the root fields, pass the gathered events to the store
def after_query(query)
  events = query.context.namespace(:subscriptions)[:events]
  if events && events.any?
    @schema.subscriptions.write_subscription(query, events)
  end
end

def before_query(query)

If needed, prepare to gather events which this query subscribes to
def before_query(query)
  if query.subscription? && !query.subscription_update?
    query.context.namespace(:subscriptions)[:events] = []
  end
end

def initialize(schema:)

def initialize(schema:)
  @schema = schema
end