Add DateTime champ to GraphQL

This commit is contained in:
Paul Chavard 2020-12-18 11:21:03 +01:00
parent d509fe2edb
commit dc08993a89
6 changed files with 144 additions and 3 deletions

View file

@ -43,6 +43,7 @@ class Api::V2::Schema < GraphQL::Schema
Types::Champs::CheckboxChampType,
Types::Champs::CiviliteChampType,
Types::Champs::DateChampType,
Types::Champs::DatetimeChampType,
Types::Champs::DecimalNumberChampType,
Types::Champs::DossierLinkChampType,
Types::Champs::IntegerNumberChampType,

View file

@ -180,6 +180,33 @@ type CreateDirectUploadPayload {
}
type DateChamp implements Champ {
"""
La valeur du champ formaté en ISO8601 (Date).
"""
date: ISO8601Date
id: ID!
"""
Libellé du champ.
"""
label: String!
"""
La valeur du champ sous forme texte.
"""
stringValue: String
"""
La valeur du champ formaté en ISO8601 (DateTime).
"""
value: ISO8601DateTime @deprecated(reason: "Utilisez le champ 'date' ou le fragment 'DatetimeChamp' à la place.")
}
type DatetimeChamp implements Champ {
"""
La valeur du champ formaté en ISO8601 (DateTime).
"""
datetime: ISO8601DateTime
id: ID!
"""
@ -191,7 +218,6 @@ type DateChamp implements Champ {
La valeur du champ sous forme texte.
"""
stringValue: String
value: ISO8601DateTime
}
type DecimalNumberChamp implements Champ {

View file

@ -11,8 +11,14 @@ module Types
case object
when ::Champs::EngagementChamp, ::Champs::YesNoChamp, ::Champs::CheckboxChamp
Types::Champs::CheckboxChampType
when ::Champs::DateChamp, ::Champs::DatetimeChamp
when ::Champs::DateChamp
Types::Champs::DateChampType
when ::Champs::DatetimeChamp
if context.has_fragment?(:DatetimeChamp)
Types::Champs::DatetimeChampType
else
Types::Champs::DateChampType
end
when ::Champs::DossierLinkChamp
Types::Champs::DossierLinkChampType
when ::Champs::PieceJustificativeChamp

View file

@ -2,12 +2,19 @@ module Types::Champs
class DateChampType < Types::BaseObject
implements Types::ChampType
field :value, GraphQL::Types::ISO8601DateTime, null: true
field :value, GraphQL::Types::ISO8601DateTime, "La valeur du champ formaté en ISO8601 (DateTime).", null: true, deprecation_reason: "Utilisez le champ 'date' ou le fragment 'DatetimeChamp' à la place."
field :date, GraphQL::Types::ISO8601Date, "La valeur du champ formaté en ISO8601 (Date).", null: true
def value
if object.value.present?
Time.zone.parse(object.value)
end
end
def date
if object.value.present?
Date.parse(object.value)
end
end
end
end

View file

@ -0,0 +1,13 @@
module Types::Champs
class DatetimeChampType < Types::BaseObject
implements Types::ChampType
field :datetime, GraphQL::Types::ISO8601DateTime, "La valeur du champ formaté en ISO8601 (DateTime).", null: true
def datetime
if object.value.present?
Time.zone.parse(object.value)
end
end
end
end