Class: Rails::GraphQL::Type::Scalar::DateScalar
- Inherits:
-
Rails::GraphQL::Type::Scalar
- Object
- Rails::GraphQL::Type
- Rails::GraphQL::Type::Scalar
- Rails::GraphQL::Type::Scalar::DateScalar
- Defined in:
- lib/rails/graphql/type/scalar/date_scalar.rb
Overview
Date uses a ISO 8601 string to exchange the value.
Constant Summary
Constants inherited from Rails::GraphQL::Type
Class Method Summary collapse
- .as_json(value) ⇒ Object
- .deserialize(value) ⇒ Object
- .valid_input?(value) ⇒ Boolean
- .valid_output?(value) ⇒ Boolean
Methods inherited from Rails::GraphQL::Type::Scalar
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
25 26 27 |
# File 'lib/rails/graphql/type/scalar/date_scalar.rb', line 25 def as_json(value) value.to_date.iso8601 end |
.deserialize(value) ⇒ Object
29 30 31 |
# File 'lib/rails/graphql/type/scalar/date_scalar.rb', line 29 def deserialize(value) Date.iso8601(value) end |
.valid_input?(value) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/rails/graphql/type/scalar/date_scalar.rb', line 13 def valid_input?(value) super && !!Date.iso8601(value) rescue Date::Error false end |
.valid_output?(value) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/rails/graphql/type/scalar/date_scalar.rb', line 19 def valid_output?(value) value.respond_to?(:to_date) && !!value.to_date rescue Date::Error false end |