I'm upgrading from 1.8.7 to 1.8.17 and I'm running into this issue.
It used to be possible to mutate using a Date (not DateTime) value, but this commit broke it, it seems:
https://github.com/rmosolgo/graphql-ruby/commit/b7af23dad3ceeeab3cf605e654134e51112e4a1d#diff-de806a69bbb13a0720a14fa6844560b3
Here is the backtrace:
ArgumentError:
wrong number of arguments (given 1, expected 0)
# /Users/jgesimondo/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.8.12/lib/graphql/types/iso_8601_date_time.rb:35:in `iso8601'
# /Users/jgesimondo/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.8.12/lib/graphql/types/iso_8601_date_time.rb:35:in `coerce_result'
# /Users/jgesimondo/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.8.12/lib/graphql/scalar_type.rb:92:in `call'
# /Users/jgesimondo/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.8.12/lib/graphql/scalar_type.rb:92:in `coerce_result'
The code there is:
def self.coerce_result(value, _ctx)
value.iso8601(time_precision)
end
In our case, value is a Date, (the string we are mutating with is '2020-01-23' and that gets casted to a Date) which does not accept arguments to its iso8601 method, and therefore raises this error.
Before I go shouting REGRESSION!, the thing is... I don't know if graphql was ever meant to support dates, but it did until this commit, and no longer. And, well, that'd be great if it did again :)
It is DateTime type. But you can do something similar for Date. It does not require time precision.
class ISO8601Date < GraphQL::Schema::Scalar
description 'An ISO 8601-encoded date'
def self.coerce_input(input_value, _context)
Date.iso8601(input_value)
rescue ArgumentError
nil
end
def self.coerce_result(ruby_value, _context)
ruby_value.iso8601
end
end
thanks this is helpful.
Most helpful comment
It is
DateTimetype. But you can do something similar forDate. It does not require time precision.