Class: Rails::GraphQL::GlobalID::Serializer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rails/graphql/global_id.rb

Overview

This adds support to ActiveJob serialization, which can be used to pass GraphQL objects to jobs and also deserialize things for subscriptions

Instance Method Summary collapse

Instance Method Details

#deserialize(argument) ⇒ Object

Deserializes an argument from a JSON primitive type.



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

def deserialize(argument)
  GlobalID.find argument[GlobalID::SERIALIZER_KEY]
end

#serialize(argument) ⇒ Object

Serializes an argument to a JSON primitive type.



32
33
34
# File 'lib/rails/graphql/global_id.rb', line 32

def serialize(argument)
  { GlobalID::SERIALIZER_KEY => argument.to_global_id.to_s }
end

#serialize?(argument) ⇒ Boolean

Determines if an argument should be serialized by this serializer.

Returns:

  • (Boolean)


27
28
29
# File 'lib/rails/graphql/global_id.rb', line 27

def serialize?(argument)
  argument.is_a?(Helpers::WithGlobalID) || argument.class.is_a?(Helpers::WithGlobalID)
end