class GraphQL::Subscriptions::Event
This thing can be: - Subscribed to by subscription { ... } - Triggered by MySchema.subscriber.trigger(name, arguments, obj)
Attributes
Returns
Returns
-
String— Corresponds to the Subscription root field name
Returns
-
String— An opaque string which identifies this event, derived fromnameandarguments
Public Class Methods
# File lib/graphql/subscriptions/event.rb, line 83 def arguments_without_field_extras(arguments:, field:) if !field.extras.empty? arguments = arguments.dup field.extras.each do |extra_key| arguments.delete(extra_key) end end arguments end
# File lib/graphql/subscriptions/event.rb, line 30 def initialize(name:, arguments:, field: nil, context: nil, scope: nil) @name = name @arguments = self.class.arguments_without_field_extras(arguments: arguments, field: field) @context = context field ||= context.field scope_key = field.subscription_scope scope_val = scope || (context && scope_key && context[scope_key]) if scope_key && (subscription = field.resolver) && (subscription.respond_to?(:subscription_scope_optional?)) && !subscription.subscription_scope_optional? && scope_val.nil? raise Subscriptions::SubscriptionScopeMissingError, "#{field.path} (#{subscription}) requires a `scope:` value to trigger updates (Set `subscription_scope ..., optional: true` to disable this requirement)" end @topic = self.class.serialize(name, arguments, field, scope: scope_val, context: context) end
# File lib/graphql/subscriptions/event.rb, line 54 def self.serialize(_name, arguments, field, scope:, context: GraphQL::Query::NullContext.instance) subscription = field.resolver || GraphQL::Schema::Subscription arguments = arguments_without_field_extras(field: field, arguments: arguments) normalized_args = stringify_args(field, arguments.to_h, context) subscription.topic_for(arguments: normalized_args, field: field, scope: scope) end
Returns
-
String— an identifier for this unit of subscription
Public Instance Methods
Source
# File lib/graphql/subscriptions/event.rb, line 67 def fingerprint @fingerprint ||= begin # When this query has been flagged as broadcastable, # use a generalized, stable fingerprint so that # duplicate subscriptions can be evaluated and distributed in bulk. # (`@topic` includes field, args, and subscription scope already.) if @context.namespace(:subscriptions)[:subscription_broadcastable] "#{@topic}/#{@context.query.fingerprint}" else # not broadcastable, build a unique ID for this event @context.schema.subscriptions.build_id end end end
Returns
-
String— a logical identifier for this event. (Stable when the query is broadcastable.)