Module: GraphQL::Schema::UniqueWithinType

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

Constant Summary collapse

DEFAULT_SEPARATOR =
"-"

Class Method Summary collapse

Class Method Details

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


23
24
25
# File 'lib/graphql/schema/unique_within_type.rb', line 23

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

.encode(type_name, object_value, separator: DEFAULT_SEPARATOR) ⇒ String


11
12
13
14
15
16
17
18
19
# File 'lib/graphql/schema/unique_within_type.rb', line 11

def encode(type_name, object_value, separator: DEFAULT_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