class GraphQL::Subscriptions::Event

This thing can be:

An array of `Event`s are passed to `store.register(query, events)`.

Attributes

arguments[R]

@return [GraphQL::Query::Arguments]

context[R]

@return [GraphQL::Query::Context]

name[R]

@return [String] Corresponds to the Subscription root field name

topic[R]

@return [String] An opaque string which identifies this event, derived from `name` and `arguments`

Public Class Methods

new(name:, arguments:, field: nil, context: nil, scope: nil) click to toggle source
# 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
serialize(name, arguments, field, scope:) click to toggle source

@return [String] an identifier for this unit of subscription

# 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
    GraphQL::Query::LiteralInput.from_arguments(
      arguments,
      field,
      nil,
    )
  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