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


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

def default_id_separator
  @default_id_separator
end

Class Method Details

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


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

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

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


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

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

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

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