Class: Rails::GraphQL::Type::Scalar::IdScalar
- Inherits:
-
Rails::GraphQL::Type::Scalar
- Object
- Rails::GraphQL::Type
- Rails::GraphQL::Type::Scalar
- Rails::GraphQL::Type::Scalar::IdScalar
- Defined in:
- lib/rails/graphql/type/scalar/id_scalar.rb
Overview
The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a StringScalar
.
Constant Summary
Constants inherited from Rails::GraphQL::Type
Class Method Summary collapse
Methods inherited from Rails::GraphQL::Type::Scalar
inspect, to_json, valid_output?
Methods inherited from Rails::GraphQL::Type
=~, base_type, create!, decorate, find_by_gid, gid_base_class, input_type?, kind, kind_enum, leaf_type?, operational?, output_type?, to_gql_backtrace
Methods included from Helpers::WithDirectives
#all_directive_events, #all_directive_listeners, #directive_events?, #directive_listeners?, extended, included, #initialize_copy, #use, #using?, #validate!
Methods included from Helpers::WithGlobalID
Methods included from Helpers::Registerable
#aliases, extended, #inherited, #register!, #registered?
Class Method Details
.as_json(value) ⇒ Object
27 28 29 30 31 |
# File 'lib/rails/graphql/type/scalar/id_scalar.rb', line 27 def as_json(value) value = value.to_s unless value.is_a?(String) value = value.encode(Encoding::UTF_8) unless value.encoding.eql?(Encoding::UTF_8) value end |
.deserialize(value) ⇒ Object
33 34 35 |
# File 'lib/rails/graphql/type/scalar/id_scalar.rb', line 33 def deserialize(value) valid_token?(value, :string) ? value[1..-2] : value end |
.valid_input?(value) ⇒ Boolean
22 23 24 25 |
# File 'lib/rails/graphql/type/scalar/id_scalar.rb', line 22 def valid_input?(value) valid_token?(value, :string) || valid_token?(value, :int) || value.is_a?(String) || value.is_a?(Integer) end |