module GraphQL::Schema::UniqueWithinType

Attributes

default_id_separator[RW]

Public Instance Methods

decode(node_id, separator: self.default_id_separator) click to toggle source

@param node_id [String] A unique ID generated by {.encode} @return [Array<(String, String)>] The type name & value passed to {.encode}

# 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) click to toggle source

@param type_name [String] @param object_value [Any] @return [String] a unique, opaque ID generated as a function of the two inputs

# 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