diff --git a/app/graphql/types/date.rb b/app/graphql/types/date.rb new file mode 100644 index 00000000..531a4020 --- /dev/null +++ b/app/graphql/types/date.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Types + class Date < Types::BaseScalar + graphql_name "Date" + description "An ISO 8601-encoded date" + + def self.coerce_input(value, _context) + begin + ::Date.iso8601(value.to_s) + rescue ArgumentError + raise GraphQL::CoercionError, "cannot coerce `#{value.inspect}` to Date" + end + end + + def self.coerce_result(value, _context) + value + end + end +end \ No newline at end of file diff --git a/app/graphql/types/goal_type.rb b/app/graphql/types/goal_type.rb index c768bd5a..fe735126 100644 --- a/app/graphql/types/goal_type.rb +++ b/app/graphql/types/goal_type.rb @@ -11,7 +11,7 @@ class GoalType < BaseObject field :amount, Int, null: false, description: 'The amount of kudos that is required to reach the goal' - field :achieved_on, GraphQL::Types::ISO8601DateTime, + field :achieved_on, Types::Date, null: true, description: 'The date the goal is achieved' field :kudos_meter, Types::KudosMeterType,