Module: GraphQL::Subscriptions::Serialize Private

Defined in:
lib/graphql/subscriptions/serialize.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Serialization helpers for passing subscription data around.

Constant Summary collapse

GLOBALID_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"__gid__"
SYMBOL_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"__sym__"
SYMBOL_KEYS_KEY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"__sym_keys__"

Class Method Summary collapse

Class Method Details

.dump(obj) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The stringified object.

Parameters:

  • obj (Object)

    Some subscription-related data to dump

Returns:

  • (String)

    The stringified object



24
25
26
# File 'lib/graphql/subscriptions/serialize.rb', line 24

def dump(obj)
  JSON.generate(dump_value(obj), quirks_mode: true)
end

.dump_recursive(obj) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This is for turning objects into subscription scopes. It's a one-way transformation, can't reload this :'(

Parameters:

  • obj (Object)

Returns:

  • (String)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/graphql/subscriptions/serialize.rb', line 32

def dump_recursive(obj)
  case
  when obj.is_a?(Array)
    obj.map { |i| dump_recursive(i) }.join(':')
  when obj.is_a?(Hash)
    obj.map { |k, v| "#{dump_recursive(k)}:#{dump_recursive(v)}" }.join(":")
  when obj.is_a?(GraphQL::Schema::InputObject)
    dump_recursive(obj.to_h)
  when obj.respond_to?(:to_gid_param)
    obj.to_gid_param
  when obj.respond_to?(:to_param)
    obj.to_param
  else
    obj.to_s
  end
end

.load(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns An object equivalent to the one passed to dump.

Parameters:

  • str (String)

    A serialized object from dump

Returns:

  • (Object)

    An object equivalent to the one passed to dump



17
18
19
20
# File 'lib/graphql/subscriptions/serialize.rb', line 17

def load(str)
  parsed_obj = JSON.parse(str)
  load_value(parsed_obj)
end