From 210becd24c67bceb3d542fd6145d3962ec6683be Mon Sep 17 00:00:00 2001 From: Matthijs Groen Date: Thu, 10 Oct 2024 13:43:34 +0200 Subject: [PATCH] Update date type --- app/graphql/types/date.rb | 20 ++++++++++++++++++++ app/graphql/types/goal_type.rb | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/graphql/types/date.rb 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,