Class: GraphQL::Types::ISO8601DateTime
- Inherits:
-
Schema::Scalar
- Object
- Schema::Member
- Schema::Scalar
- GraphQL::Types::ISO8601DateTime
- Defined in:
- lib/graphql/types/iso_8601_date_time.rb
Overview
This scalar takes DateTime
s and transmits them as strings,
using ISO 8601 format.
Use it for fields or arguments as follows:
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
argument :deliver_at, GraphQL::Types::ISO8601DateTime, null: false
Alternatively, use this built-in scalar as inspiration for your own DateTime type.
Constant Summary
- DEFAULT_TIME_PRECISION =
It’s not compatible with Rails’ default, i.e. ActiveSupport::JSON::Encoder.time_precision (3 by default)
0
Constants included from Schema::Member::GraphQLTypeNames
Schema::Member::GraphQLTypeNames::Boolean, Schema::Member::GraphQLTypeNames::ID, Schema::Member::GraphQLTypeNames::Int
Class Method Summary collapse
-
.coerce_input(str_value, _ctx) ⇒ DateTime
-
.coerce_result(value, _ctx) ⇒ String
-
.time_precision ⇒ Integer
-
.time_precision=(value) ⇒ Object
Methods inherited from Schema::Scalar
default_scalar, kind, to_graphql
Methods included from Schema::Member::HasPath
Methods included from Schema::Member::RelayShortcuts
#connection_type, #connection_type_class, #edge_type, #edge_type_class
Methods included from Schema::Member::Scoped
Methods included from Schema::Member::TypeSystemHelpers
#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
Methods included from Schema::Member::BaseDSLMethods
#accessible?, #authorized?, #default_graphql_name, #description, #graphql_name, #introspection, #mutation, #name, #overridden_graphql_name, #to_graphql, #visible?
Methods included from Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Schema::Member::CachedGraphQLDefinition
#graphql_definition, #initialize_copy
Class Method Details
.coerce_input(str_value, _ctx) ⇒ DateTime
40 41 42 43 44 45 |
# File 'lib/graphql/types/iso_8601_date_time.rb', line 40 def self.coerce_input(str_value, _ctx) DateTime.iso8601(str_value) rescue ArgumentError # Invalid input nil end |
.coerce_result(value, _ctx) ⇒ String
34 35 36 |
# File 'lib/graphql/types/iso_8601_date_time.rb', line 34 def self.coerce_result(value, _ctx) value.iso8601(time_precision) end |
.time_precision ⇒ Integer
23 24 25 |
# File 'lib/graphql/types/iso_8601_date_time.rb', line 23 def self.time_precision @time_precision || DEFAULT_TIME_PRECISION end |
.time_precision=(value) ⇒ Object
28 29 30 |
# File 'lib/graphql/types/iso_8601_date_time.rb', line 28 def self.time_precision=(value) @time_precision = value end |