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__"
TIMESTAMP_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.

"__timestamp__"
TIMESTAMP_FORMAT =

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.

eg '2020-01-01 23:59:59.123456789+05:00'

"%Y-%m-%d %H:%M:%S.%N%Z"
OPEN_STRUCT_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.

"__ostruct__"

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


27
28
29
# File 'lib/graphql/subscriptions/serialize.rb', line 27

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)

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

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


20
21
22
23
# File 'lib/graphql/subscriptions/serialize.rb', line 20

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