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)
An array of Event
s are passed to store.register(query, events)
.
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
-
#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
23 24 25 26 27 28 29 30 31 |
# File 'lib/graphql/subscriptions/event.rb', line 23 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)
15 16 17 |
# File 'lib/graphql/subscriptions/event.rb', line 15 def arguments @arguments end |
#context ⇒ GraphQL::Query::Context (readonly)
18 19 20 |
# File 'lib/graphql/subscriptions/event.rb', line 18 def context @context end |
#name ⇒ String (readonly)
Returns Corresponds to the Subscription root field name
12 13 14 |
# File 'lib/graphql/subscriptions/event.rb', line 12 def name @name end |
#topic ⇒ String (readonly)
Returns An opaque string which identifies this event, derived from name
and arguments
21 22 23 |
# File 'lib/graphql/subscriptions/event.rb', line 21 def topic @topic end |
Class Method Details
.serialize(name, arguments, field, scope:) ⇒ String
Returns an identifier for this unit of subscription
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/graphql/subscriptions/event.rb', line 34 def self.serialize(name, arguments, field, scope:) normalized_args = case arguments when GraphQL::Query::Arguments arguments when Hash if field.is_a?(GraphQL::Schema::Field) stringify_args(field, arguments) else GraphQL::Query::LiteralInput.from_arguments( arguments, field, nil, ) end else raise ArgumentError, "Unexpected arguments: #{arguments}, must be Hash or GraphQL::Arguments" end sorted_h = normalized_args.to_h.sort.to_h Serialize.dump_recursive([scope, name, sorted_h]) end |