Class: GraphQL::Types::ISO8601Date
- Inherits:
-
Schema::Scalar
- Object
- Schema::Member
- Schema::Scalar
- GraphQL::Types::ISO8601Date
- Defined in:
- lib/graphql/types/iso_8601_date.rb
Overview
This scalar takes Dates and transmits them as strings,
using ISO 8601 format.
Use it for fields or arguments as follows:
field :published_at, GraphQL::Types::ISO8601Date, null: false
argument :deliver_at, GraphQL::Types::ISO8601Date, null: false
Alternatively, use this built-in scalar as inspiration for your own Date type.
Constant Summary
Constants included from Schema::Member::GraphQLTypeNames
Schema::Member::GraphQLTypeNames::Boolean, Schema::Member::GraphQLTypeNames::ID, Schema::Member::GraphQLTypeNames::Int
Instance Attribute Summary
Attributes included from Schema::Member::BaseDSLMethods
#default_graphql_name, #graphql_name
Attributes included from Schema::Member::RelayShortcuts
#connection_type, #connection_type_class, #edge_type, #edge_type_class
Attributes included from Schema::Member::HasAstNode
Class Method Summary collapse
-
.coerce_input(value, ctx) ⇒ Object
Parameters.
-
.coerce_result(value, _ctx) ⇒ Object
Parameters.
Methods inherited from Schema::Scalar
default_scalar, default_scalar?, kind, specified_by_url, validate_non_null_input
Methods included from Schema::Member::ValidatesInput
#coerce_isolated_input, #coerce_isolated_result, #valid_input?, #valid_isolated_input?, #validate_input
Methods inherited from Schema::Member
Methods included from Schema::Member::BaseDSLMethods
#authorized?, #comment, #default_relay?, #description, #introspection, #introspection?, #mutation, #visible?
Methods included from Schema::FindInheritedValue
Methods included from Schema::Member::BaseDSLMethods::ConfigurationExtension
Methods included from Schema::Member::TypeSystemHelpers
#initialize, #kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
Methods included from Schema::Member::Scoped
#inherited, #reauthorize_scoped_objects, #scope_items
Methods included from Schema::Member::HasPath
Methods included from Schema::Member::HasAstNode
Methods included from Schema::Member::HasDirectives
add_directive, #directive, #directives, extended, get_directives, #inherited, #remove_directive, remove_directive
Class Method Details
.coerce_input(value, ctx) ⇒ Object
Parameters
str_value(String, Date, DateTime, Time)
Returns
Date, nil
:call-seq:
coerce_input(value, ctx) -> Date | nil
: (untyped value, GraphQL::Query::Context ctx) -> untyped
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/graphql/types/iso_8601_date.rb', line 47 def self.coerce_input(value, ctx) if value.is_a?(::Date) value elsif value.is_a?(::DateTime) value.to_date elsif value.is_a?(::Time) value.to_date elsif value.nil? nil else Date.iso8601(value) end rescue ArgumentError, TypeError err = GraphQL::DateEncodingError.new(value) ctx.schema.type_error(err, ctx) end |
.coerce_result(value, _ctx) ⇒ Object
Parameters
value(Date, Time, DateTime, String)
Returns
String
:call-seq:
coerce_result(Date | Time | DateTime | String value, _ctx) -> String
: (untyped value, GraphQL::Query::Context _ctx) -> ::String
32 33 34 |
# File 'lib/graphql/types/iso_8601_date.rb', line 32 def self.coerce_result(value, _ctx) Date.parse(value.to_s).iso8601 end |