Class: Rails::GraphQL::Request::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/graphql/request/subscription.rb

Overview

GraphQL Request Subscription

A simple object to store information about a generated subscription TODO: Maybe add a callback for the schema allowing it to prepare the context before saving it into a subscription

Constant Summary collapse

NULL_SCOPE =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, operation) ⇒ Subscription

Returns a new instance of Subscription.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rails/graphql/request/subscription.rb', line 20

def initialize(request, operation)
  entrypoint = operation.selection.each_value.first            # Memory Fingerprint

  @schema = request.schema.namespace                           # 1 Symbol
  @origin = request.origin                                     # * HEAVY!
  @operation_id = operation.hash                               # 1 Integer
  @args = entrypoint.arguments.to_h                            # 1 Hash of GQL values
  @field = entrypoint.field                                    # 1 Pointer
  @context = request.context.to_h                              # 1 Hash +/- heavy
  @broadcastable = operation.broadcastable?                    # 1 Boolean
  @created_at = Time.current                                   # 1 Integer
  updated!                                                     # 1 Integer

  @scope = parse_scope(field.full_scope, request, operation)   # 1 Integer after save
  @sid = request.schema.subscription_id_for(self)              # 1 String
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def args
  @args
end

#broadcastableObject (readonly) Also known as: broadcastable?

Returns the value of attribute broadcastable.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def broadcastable
  @broadcastable
end

#contextObject (readonly)

Returns the value of attribute context.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def context
  @context
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def created_at
  @created_at
end

#fieldObject (readonly)

Returns the value of attribute field.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def field
  @field
end

#operation_idObject (readonly)

Returns the value of attribute operation_id.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def operation_id
  @operation_id
end

#originObject (readonly)

Returns the value of attribute origin.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def origin
  @origin
end

#schemaObject (readonly)

Returns the value of attribute schema.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def schema
  @schema
end

#scopeObject (readonly)

Returns the value of attribute scope.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def scope
  @scope
end

#sidObject (readonly) Also known as: id

Returns the value of attribute sid.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def sid
  @sid
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



14
15
16
# File 'lib/rails/graphql/request/subscription.rb', line 14

def updated_at
  @updated_at
end

Instance Method Details

#inspectObject



45
46
47
48
49
50
51
52
# File 'lib/rails/graphql/request/subscription.rb', line 45

def inspect
  (+"    #<\#{self.class.name}\n    \#{schema}@\#{sid}\n    [\#{scope.inspect}, \#{args.hash}]\n    \#{field.inspect}\n  INFO\nend\n").squish << '>'

#marshal_dumpObject

Raises:

  • (::TypeError)


41
42
43
# File 'lib/rails/graphql/request/subscription.rb', line 41

def marshal_dump
  raise ::TypeError, +"Request subscriptions must not be used as payload."
end

#updated!Object



37
38
39
# File 'lib/rails/graphql/request/subscription.rb', line 37

def updated!
  @updated_at = Time.current
end