Method: GraphQL::Types::ISO8601DateTime.coerce_result

Defined in:
lib/graphql/types/iso_8601_date_time.rb

.coerce_result(value, _ctx) ⇒ String

Parameters:

  • value (Time, Date, DateTime, String)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/graphql/types/iso_8601_date_time.rb', line 38

def self.coerce_result(value, _ctx)
  case value
  when Date
    return value.to_time.iso8601(time_precision)
  when ::String
    return Time.parse(value).iso8601(time_precision)
  else
    # Time, DateTime or compatible 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 Times, Dates, DateTimes, and well-formatted Strings are used with this type. (#{error.message})"
end