Module: GraphQL::Schema::UniqueWithinType

Defined in:
lib/graphql/schema/unique_within_type.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_id_separatorObject

Returns the value of attribute default_id_separator.



6
7
8
# File 'lib/graphql/schema/unique_within_type.rb', line 6

def default_id_separator
  @default_id_separator
end

Class Method Details

.decode(node_id, separator: self.default_id_separator) ⇒ Array<(String, String)>

Returns The type name & value passed to encode.

Parameters:

  • node_id (String)

    A unique ID generated by encode

Returns:

  • (Array<(String, String)>)

    The type name & value passed to encode



27
28
29
# File 'lib/graphql/schema/unique_within_type.rb', line 27

def decode(node_id, separator: self.default_id_separator)
  Base64.decode64(node_id).split(separator, 2)
end

.encode(type_name, object_value, separator: self.default_id_separator) ⇒ String

Returns a unique, opaque ID generated as a function of the two inputs.

Parameters:

  • type_name (String)
  • object_value (Any)

Returns:

  • (String)

    a unique, opaque ID generated as a function of the two inputs



15
16
17
18
19
20
21
22
23
# File 'lib/graphql/schema/unique_within_type.rb', line 15

def encode(type_name, object_value, separator: self.default_id_separator)
  object_value_str = object_value.to_s

  if type_name.include?(separator)
    raise "encode(#{type_name}, #{object_value_str}) contains reserved characters `#{separator}` in the type name"
  end

  Base64.strict_encode64([type_name, object_value_str].join(separator))
end