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.



8
9
10
# File 'lib/graphql/schema/unique_within_type.rb', line 8

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



29
30
31
32
# File 'lib/graphql/schema/unique_within_type.rb', line 29

def decode(node_id, separator: self.default_id_separator)
  # urlsafe_decode64 is for forward compatibility
  Base64Bp.urlsafe_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



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

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