Skip to content

Draft: GraphQL: Return nil instead of GraphQL::CoercionError for TimeType

Brett Walker requested to merge bw-time-type-coerce into master

What does this MR do and why?

The graphql gem returns nil when attempting to coerce_input with an invalid value, such as in https://github.com/rmosolgo/graphql-ruby/blob/c44aee192734a3b762d6030ed4a1cb352724ffc9/lib/graphql/types/iso_8601_date_time.rb#L53

      # @param str_value [String]
      # @return [Time]
      def self.coerce_input(str_value, _ctx)
        Time.iso8601(str_value)
      rescue ArgumentError, TypeError
        begin
          Date.iso8601(str_value).to_time
        rescue ArgumentError, TypeError
          # Invalid input
          nil
        end
      end
    end

Our types should behave consistently with the gem's types. This also fixes a problem during the conversion in [graphql] Convert to using the new query interp... (!27536 - merged)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports