Class: GraphQL::Subscriptions::SubscriptionRoot::Extension Private

Inherits:
GraphQL::Schema::FieldExtension show all
Defined in:
lib/graphql/subscriptions/subscription_root.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Direct Known Subclasses

DefaultSubscriptionResolveExtension

Instance Attribute Summary

Attributes inherited from GraphQL::Schema::FieldExtension

#field, #options

Instance Method Summary collapse

Methods inherited from GraphQL::Schema::FieldExtension

#apply, #initialize, #resolve

Constructor Details

This class inherits a constructor from GraphQL::Schema::FieldExtension

Instance Method Details

#after_resolve(value:, context:, object:, arguments:, **rest) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/graphql/subscriptions/subscription_root.rb', line 37

def after_resolve(value:, context:, object:, arguments:, **rest)
  if value.is_a?(GraphQL::ExecutionError)
    value
  elsif (events = context.namespace(:subscriptions)[:events])
    # This is the first execution, so gather an Event
    # for the backend to register:
    event = Subscriptions::Event.new(
      name: field.name,
      arguments: arguments_without_field_extras(arguments: arguments),
      context: context,
      field: field,
    )
    events << event
    value
  elsif context.query.subscription_topic == Subscriptions::Event.serialize(
      field.name,
      arguments_without_field_extras(arguments: arguments),
      field,
      scope: (field.subscription_scope ? context[field.subscription_scope] : nil),
    )
    # This is a subscription update. The resolver returned `skip` if it should be skipped,
    # or else it returned an object to resolve the update.
    value
  else
    # This is a subscription update, but this event wasn't triggered.
    context.skip
  end
end