class GraphQL::Types::ISO8601DateTime
own DateTime type.
Alternatively, use this built-in scalar as inspiration for your
argument :deliver_at, GraphQL::Types::ISO8601DateTime, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
Use it for fields or arguments as follows:
using ISO 8601 format.
This scalar takes ‘DateTime`s and transmits them as strings,
def self.coerce_input(str_value, _ctx)
-
(DateTime)
-
Parameters:
-
str_value
(String
) --
def self.coerce_input(str_value, _ctx) DateTime.iso8601(str_value) rescue ArgumentError # Invalid input nil end
def self.coerce_result(value, _ctx)\
-
(String)
-
Parameters:
-
value
(Date, DateTime, String
) --
def self.coerce_result(value, _ctx)\ case value when DateTime return value.iso8601(time_precision) when Date return DateTime.parse(value.to_s).iso8601(time_precision) when ::String return DateTime.parse(value).iso8601(time_precision) else # In case some other API-compliant thing is given: return value.iso8601(time_precision) end rescue StandardError => error raise GraphQL::Error, "An incompatible object (#{value.class}) was given to #{self}. Make sure that only Dates, DateTimes, and well-formatted Strings are used with this type. (#{error.message})" end
def self.time_precision
-
(Integer)
-
def self.time_precision @time_precision || DEFAULT_TIME_PRECISION end
def self.time_precision=(value)
-
value
(Integer
) --
def self.time_precision=(value) @time_precision = value end