Method: GraphQL::Types::ISO8601Duration.coerce_input

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

.coerce_input(value, ctx) ⇒ ActiveSupport::Duration?

Parameters:

  • value (String, ActiveSupport::Duration)

Returns:

  • (ActiveSupport::Duration, nil)

Raises:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/graphql/types/iso_8601_duration.rb', line 57

def self.coerce_input(value, ctx)
  unless defined?(ActiveSupport::Duration)
    raise GraphQL::Error, "ActiveSupport >= 5.0 must be loaded to use the built-in ISO8601Duration type."
  end

  begin
    if value.is_a?(ActiveSupport::Duration)
      value
    elsif value.nil?
      nil
    else
      ActiveSupport::Duration.parse(value)
    end
  rescue ArgumentError, TypeError
    err = GraphQL::DurationEncodingError.new(value)
    ctx.schema.type_error(err, ctx)
  end
end