Class: GraphQL::Subscriptions::Event
- Inherits:
-
Object
- Object
- GraphQL::Subscriptions::Event
- Defined in:
- lib/graphql/subscriptions/event.rb
Overview
This thing can be:
- Subscribed to by subscription { ... }
- Triggered by MySchema.subscriber.trigger(name, arguments, obj)
Instance Attribute Summary collapse
-
#arguments ⇒ GraphQL::Query::Arguments
readonly
-
#context ⇒ GraphQL::Query::Context
readonly
-
#name ⇒ String
readonly
Corresponds to the Subscription root field name.
-
#topic ⇒ String
readonly
An opaque string which identifies this event, derived from
name
andarguments
.
Class Method Summary collapse
-
.serialize(_name, arguments, field, scope:) ⇒ String
An identifier for this unit of subscription.
Instance Method Summary collapse
-
#fingerprint ⇒ String
A logical identifier for this event.
-
#initialize(name:, arguments:, field: nil, context: nil, scope: nil) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(name:, arguments:, field: nil, context: nil, scope: nil) ⇒ Event
Returns a new instance of Event.
21 22 23 24 25 26 27 28 29 |
# File 'lib/graphql/subscriptions/event.rb', line 21 def initialize(name:, arguments:, field: nil, context: nil, scope: nil) @name = name @arguments = arguments @context = context field ||= context.field scope_val = scope || (context && field.subscription_scope && context[field.subscription_scope]) @topic = self.class.serialize(name, arguments, field, scope: scope_val) end |
Instance Attribute Details
#arguments ⇒ GraphQL::Query::Arguments (readonly)
13 14 15 |
# File 'lib/graphql/subscriptions/event.rb', line 13 def arguments @arguments end |
#context ⇒ GraphQL::Query::Context (readonly)
16 17 18 |
# File 'lib/graphql/subscriptions/event.rb', line 16 def context @context end |
#name ⇒ String (readonly)
Returns Corresponds to the Subscription root field name.
10 11 12 |
# File 'lib/graphql/subscriptions/event.rb', line 10 def name @name end |
#topic ⇒ String (readonly)
Returns An opaque string which identifies this event, derived from name
and arguments
.
19 20 21 |
# File 'lib/graphql/subscriptions/event.rb', line 19 def topic @topic end |
Class Method Details
.serialize(_name, arguments, field, scope:) ⇒ String
Returns an identifier for this unit of subscription.
32 33 34 35 36 |
# File 'lib/graphql/subscriptions/event.rb', line 32 def self.serialize(_name, arguments, field, scope:) subscription = field.resolver || GraphQL::Schema::Subscription normalized_args = stringify_args(field, arguments.to_h) subscription.topic_for(arguments: normalized_args, field: field, scope: scope) end |
Instance Method Details
#fingerprint ⇒ String
Returns a logical identifier for this event. (Stable when the query is broadcastable.).
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/graphql/subscriptions/event.rb', line 39 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 |