2018-09-11 19:08:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-23 07:55:14 +00:00
|
|
|
module Types
|
|
|
|
class TimeType < BaseScalar
|
|
|
|
graphql_name 'Time'
|
2021-03-12 09:09:06 +00:00
|
|
|
description <<~DESC
|
|
|
|
Time represented in ISO 8601.
|
|
|
|
|
|
|
|
For example: "2021-03-09T14:58:50+00:00".
|
|
|
|
|
|
|
|
See `https://www.iso.org/iso-8601-date-and-time-format.html`.
|
|
|
|
DESC
|
2017-08-16 13:04:41 +00:00
|
|
|
|
2018-05-23 07:55:14 +00:00
|
|
|
def self.coerce_input(value, ctx)
|
2022-06-01 18:09:44 +00:00
|
|
|
# arguments can be nil, so don't raise an error
|
|
|
|
return if value.nil?
|
|
|
|
|
2018-05-23 07:55:14 +00:00
|
|
|
Time.parse(value)
|
2020-08-07 21:10:07 +00:00
|
|
|
rescue ArgumentError, TypeError => e
|
|
|
|
raise GraphQL::CoercionError, e.message
|
2018-05-23 07:55:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.coerce_result(value, ctx)
|
|
|
|
value.iso8601
|
|
|
|
end
|
|
|
|
end
|
2017-08-16 13:04:41 +00:00
|
|
|
end
|