Module: GraphQL::Schema::UniqueWithinType

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

Overview

-- @requires_ancestor: Kernel

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_id_separator ⇒ Object

Returns the value of attribute default_id_separator.



12
13
14
# File 'lib/graphql/schema/unique_within_type.rb', line 12

def default_id_separator
  @default_id_separator
end

Class Method Details

.decode(node_id, separator: self.default_id_separator) ⇒ Object

Parameters

  • node_id (String) — A unique ID generated by .encode

Returns

  • Array<(String, String)> — The type name & value passed to .encode

:call-seq:

decode(String node_id, separator:) -> Array[(String, String)]


49
50
51
# File 'lib/graphql/schema/unique_within_type.rb', line 49

def decode(node_id, separator: self.default_id_separator)
  GraphQL::Schema::Base64Encoder.decode(node_id).split(separator, 2)
end

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

Parameters

  • type_name (String)
  • object_value (Any)

Returns

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

:call-seq:

encode(String type_name, Any object_value, separator:) -> String


29
30
31
32
33
34
35
36
37
# File 'lib/graphql/schema/unique_within_type.rb', line 29

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