33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/graphql/types/iso_8601_duration.rb', line 33
def self.coerce_result(value, _ctx)
unless defined?(ActiveSupport::Duration)
raise GraphQL::Error, "ActiveSupport >= 5.0 must be loaded to use the built-in ISO8601Duration type."
end
begin
case value
when ActiveSupport::Duration
value.iso8601(precision: seconds_precision)
when ::String
ActiveSupport::Duration.parse(value).iso8601(precision: seconds_precision)
else
value.iso8601(precision: seconds_precision)
end
rescue StandardError => error
raise GraphQL::Error, "An incompatible object (#{value.class}) was given to #{self}. Make sure that only ActiveSupport::Durations and well-formatted Strings are used with this type. (#{error.message})"
end
end
|