Sha256: 3fd7ba7eef77d335f13ebe2b2f9ac53345fac370dd47366f230431b1246918c0

Contents?: true

Size: 1.04 KB

Versions: 44

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true
module GraphQL
  class Schema
    module UniqueWithinType
      class << self
        attr_accessor :default_id_separator
      end
      self.default_id_separator = "-"

      module_function

      # @param type_name [String]
      # @param object_value [Any]
      # @return [String] a unique, opaque ID generated as a function of the two inputs
      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

      # @param node_id [String] A unique ID generated by {.encode}
      # @return [Array<(String, String)>] The type name & value passed to {.encode}
      def decode(node_id, separator: self.default_id_separator)
        Base64.decode64(node_id).split(separator, 2)
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
graphql-1.8.6 lib/graphql/schema/unique_within_type.rb
graphql-1.8.5 lib/graphql/schema/unique_within_type.rb
graphql-1.8.4 lib/graphql/schema/unique_within_type.rb
graphql-1.8.3 lib/graphql/schema/unique_within_type.rb
graphql-1.8.2 lib/graphql/schema/unique_within_type.rb
graphql-1.8.1 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0.pre11 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0.pre10 lib/graphql/schema/unique_within_type.rb
graphql-1.7.14 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0.pre9 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0.pre8 lib/graphql/schema/unique_within_type.rb
graphql-1.7.13 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0.pre7 lib/graphql/schema/unique_within_type.rb
graphql-1.7.12 lib/graphql/schema/unique_within_type.rb
graphql-1.7.11 lib/graphql/schema/unique_within_type.rb
graphql-1.7.10 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0.pre6 lib/graphql/schema/unique_within_type.rb
graphql-1.8.0.pre5 lib/graphql/schema/unique_within_type.rb
graphql-1.7.9 lib/graphql/schema/unique_within_type.rb