Module: GraphQL::Schema::UniqueWithinType
- Defined in:
- lib/graphql/schema/unique_within_type.rb
Constant Summary collapse
- DEFAULT_SEPARATOR =
"-"
Class Method Summary collapse
-
.decode(node_id, separator: DEFAULT_SEPARATOR) ⇒ Array<(String, String)>
The type name & value passed to UniqueWithinType.encode.
-
.encode(type_name, object_value, separator: DEFAULT_SEPARATOR) ⇒ String
A unique, opaque ID generated as a function of the two inputs.
Class Method Details
.decode(node_id, separator: DEFAULT_SEPARATOR) ⇒ Array<(String, String)>
Returns The type name & value passed to encode.
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
Returns a unique, opaque ID generated as a function of the two inputs.
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 |