Skip to content

Commit

Permalink
Update date type
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijsgroen committed Oct 10, 2024
1 parent 250b8d0 commit 210becd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/graphql/types/date.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/graphql/types/goal_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 210becd

Please sign in to comment.