refactor(graphql): make champ descriptor an interface

This commit is contained in:
Paul Chavard 2022-11-24 13:14:27 +01:00
parent 3a8a50a216
commit ed1754e1fb
38 changed files with 1717 additions and 26 deletions

View file

@ -75,7 +75,42 @@ class API::V2::Schema < GraphQL::Schema
Types::GeoAreas::ParcelleCadastraleType,
Types::GeoAreas::SelectionUtilisateurType,
Types::PersonneMoraleType,
Types::PersonnePhysiqueType
Types::PersonnePhysiqueType,
Types::Champs::Descriptor::AddressChampDescriptorType,
Types::Champs::Descriptor::AnnuaireEducationChampDescriptorType,
Types::Champs::Descriptor::CarteChampDescriptorType,
Types::Champs::Descriptor::CheckboxChampDescriptorType,
Types::Champs::Descriptor::CiviliteChampDescriptorType,
Types::Champs::Descriptor::CnafChampDescriptorType,
Types::Champs::Descriptor::CommuneChampDescriptorType,
Types::Champs::Descriptor::DateChampDescriptorType,
Types::Champs::Descriptor::DatetimeChampDescriptorType,
Types::Champs::Descriptor::DecimalNumberChampDescriptorType,
Types::Champs::Descriptor::DepartementChampDescriptorType,
Types::Champs::Descriptor::DgfipChampDescriptorType,
Types::Champs::Descriptor::DossierLinkChampDescriptorType,
Types::Champs::Descriptor::DropDownListChampDescriptorType,
Types::Champs::Descriptor::EmailChampDescriptorType,
Types::Champs::Descriptor::ExplicationChampDescriptorType,
Types::Champs::Descriptor::HeaderSectionChampDescriptorType,
Types::Champs::Descriptor::IbanChampDescriptorType,
Types::Champs::Descriptor::IntegerNumberChampDescriptorType,
Types::Champs::Descriptor::LinkedDropDownListChampDescriptorType,
Types::Champs::Descriptor::MesriChampDescriptorType,
Types::Champs::Descriptor::MultipleDropDownListChampDescriptorType,
Types::Champs::Descriptor::NumberChampDescriptorType,
Types::Champs::Descriptor::PaysChampDescriptorType,
Types::Champs::Descriptor::PhoneChampDescriptorType,
Types::Champs::Descriptor::PieceJustificativeChampDescriptorType,
Types::Champs::Descriptor::PoleEmploiChampDescriptorType,
Types::Champs::Descriptor::RegionChampDescriptorType,
Types::Champs::Descriptor::RepetitionChampDescriptorType,
Types::Champs::Descriptor::RNAChampDescriptorType,
Types::Champs::Descriptor::SiretChampDescriptorType,
Types::Champs::Descriptor::TextChampDescriptorType,
Types::Champs::Descriptor::TextareaChampDescriptorType,
Types::Champs::Descriptor::TitreIdentiteChampDescriptorType,
Types::Champs::Descriptor::YesNoChampDescriptorType
def self.unauthorized_object(error)
# Add a top-level error to the response instead of returning nil:

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,7 @@
module Types
class ChampDescriptorType < Types::BaseObject
module ChampDescriptorType
include Types::BaseInterface
class TypeDeChampType < Types::BaseEnum
TypeDeChamp.type_champs.each do |symbol_name, string_name|
value(string_name,
@ -9,24 +11,112 @@ module Types
end
global_id_field :id
field :type, TypeDeChampType, "Type de la valeur du champ.", null: false, method: :type_champ
field :label, String, "Libellé du champ.", null: false, method: :libelle
field :description, String, "Description du champ.", null: true
field :required, Boolean, "Est-ce que le champ est obligatoire ?", null: false, method: :mandatory?
field :condition, String, "Logique conditionnelle.", null: true
field :champ_descriptors, [Types::ChampDescriptorType], "Description des champs dun bloc répétable.", null: true
field :options, [String], "List des options dun champ avec selection.", null: true
field :options, [String], "List des options dun champ avec selection.", null: true, deprecation_reason: 'Utilisez le champ `DropDownListChampDescriptor.options` à la place.'
field :champ_descriptors, [Types::ChampDescriptorType], "Description des champs dun bloc répétable.", null: true, deprecation_reason: 'Utilisez le champ `RepetitionChampDescriptor.champ_descriptors` à la place.'
field :type, TypeDeChampType, "Type de la valeur du champ.", null: false, method: :type_champ, deprecation_reason: 'Utilisez le champ `__typename` à la place.'
definition_methods do
def resolve_type(object, context)
case object.type_champ
when TypeDeChamp.type_champs.fetch(:text)
Types::Champs::Descriptor::TextChampDescriptorType
when TypeDeChamp.type_champs.fetch(:textarea)
Types::Champs::Descriptor::TextareaChampDescriptorType
when TypeDeChamp.type_champs.fetch(:date)
Types::Champs::Descriptor::DateChampDescriptorType
when TypeDeChamp.type_champs.fetch(:datetime)
Types::Champs::Descriptor::DatetimeChampDescriptorType
when TypeDeChamp.type_champs.fetch(:number)
Types::Champs::Descriptor::NumberChampDescriptorType
when TypeDeChamp.type_champs.fetch(:decimal_number)
Types::Champs::Descriptor::DecimalNumberChampDescriptorType
when TypeDeChamp.type_champs.fetch(:integer_number)
Types::Champs::Descriptor::IntegerNumberChampDescriptorType
when TypeDeChamp.type_champs.fetch(:checkbox)
Types::Champs::Descriptor::CheckboxChampDescriptorType
when TypeDeChamp.type_champs.fetch(:civilite)
Types::Champs::Descriptor::CiviliteChampDescriptorType
when TypeDeChamp.type_champs.fetch(:email)
Types::Champs::Descriptor::EmailChampDescriptorType
when TypeDeChamp.type_champs.fetch(:phone)
Types::Champs::Descriptor::PhoneChampDescriptorType
when TypeDeChamp.type_champs.fetch(:address)
Types::Champs::Descriptor::AddressChampDescriptorType
when TypeDeChamp.type_champs.fetch(:yes_no)
Types::Champs::Descriptor::YesNoChampDescriptorType
when TypeDeChamp.type_champs.fetch(:drop_down_list)
Types::Champs::Descriptor::DropDownListChampDescriptorType
when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
Types::Champs::Descriptor::MultipleDropDownListChampDescriptorType
when TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
Types::Champs::Descriptor::LinkedDropDownListChampDescriptorType
when TypeDeChamp.type_champs.fetch(:communes)
Types::Champs::Descriptor::CommuneChampDescriptorType
when TypeDeChamp.type_champs.fetch(:departements)
Types::Champs::Descriptor::DepartementChampDescriptorType
when TypeDeChamp.type_champs.fetch(:regions)
Types::Champs::Descriptor::RegionChampDescriptorType
when TypeDeChamp.type_champs.fetch(:pays)
Types::Champs::Descriptor::PaysChampDescriptorType
when TypeDeChamp.type_champs.fetch(:header_section)
Types::Champs::Descriptor::HeaderSectionChampDescriptorType
when TypeDeChamp.type_champs.fetch(:explication)
Types::Champs::Descriptor::ExplicationChampDescriptorType
when TypeDeChamp.type_champs.fetch(:dossier_link)
Types::Champs::Descriptor::DossierLinkChampDescriptorType
when TypeDeChamp.type_champs.fetch(:piece_justificative)
Types::Champs::Descriptor::PieceJustificativeChampDescriptorType
when TypeDeChamp.type_champs.fetch(:rna)
Types::Champs::Descriptor::RNAChampDescriptorType
when TypeDeChamp.type_champs.fetch(:carte)
Types::Champs::Descriptor::CarteChampDescriptorType
when TypeDeChamp.type_champs.fetch(:repetition)
Types::Champs::Descriptor::RepetitionChampDescriptorType
when TypeDeChamp.type_champs.fetch(:titre_identite)
Types::Champs::Descriptor::TitreIdentiteChampDescriptorType
when TypeDeChamp.type_champs.fetch(:iban)
Types::Champs::Descriptor::IbanChampDescriptorType
when TypeDeChamp.type_champs.fetch(:siret)
Types::Champs::Descriptor::SiretChampDescriptorType
when TypeDeChamp.type_champs.fetch(:annuaire_education)
Types::Champs::Descriptor::AnnuaireEducationChampDescriptorType
when TypeDeChamp.type_champs.fetch(:cnaf)
Types::Champs::Descriptor::CnafChampDescriptorType
when TypeDeChamp.type_champs.fetch(:dgfip)
Types::Champs::Descriptor::DgfipChampDescriptorType
when TypeDeChamp.type_champs.fetch(:pole_emploi)
Types::Champs::Descriptor::PoleEmploiChampDescriptorType
when TypeDeChamp.type_champs.fetch(:mesri)
Types::Champs::Descriptor::MesriChampDescriptorType
end
end
end
def condition
Base64.urlsafe_encode64(type_de_champ.condition.to_json)
end
def champ_descriptors
if object.type_de_champ.block?
if type_de_champ.block?
Loaders::Association.for(object.class, revision_types_de_champ: :type_de_champ).load(object)
end
end
def options
if object.type_de_champ.drop_down_list?
object.type_de_champ.drop_down_list_options.reject(&:empty?)
if type_de_champ.drop_down_list?
type_de_champ.drop_down_list_options.reject(&:empty?)
end
end
private
def type_de_champ
object.type_de_champ
end
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class AddressChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class AnnuaireEducationChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class CarteChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class CheckboxChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class CiviliteChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class CnafChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class CommuneChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class DateChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class DatetimeChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class DecimalNumberChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class DepartementChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class DgfipChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class DossierLinkChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,16 @@
module Types::Champs::Descriptor
class DropDownListChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
field :options, [String], "List des options dun champ avec selection.", null: true
field :other_option, Boolean, "La selection contien loption \"Autre\".", null: true
def other_option
object.type_de_champ.drop_down_other?
end
def options
object.type_de_champ.drop_down_list_options.reject(&:empty?)
end
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class EmailChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,16 @@
module Types::Champs::Descriptor
class ExplicationChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
field :collapsible_explanation_enabled, Boolean, null: true
field :collapsible_explanation_text, String, null: true
def collapsible_explanation_enabled
object.type_de_champ.collapsible_explanation_enabled?
end
def collapsible_explanation_text
object.type_de_champ.collapsible_explanation_text
end
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class HeaderSectionChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class IbanChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class IntegerNumberChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,11 @@
module Types::Champs::Descriptor
class LinkedDropDownListChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
field :options, [String], "List des options dun champ avec selection.", null: true
def options
object.type_de_champ.drop_down_list_options.reject(&:empty?)
end
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class MesriChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,11 @@
module Types::Champs::Descriptor
class MultipleDropDownListChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
field :options, [String], "List des options dun champ avec selection.", null: true
def options
object.type_de_champ.drop_down_list_options.reject(&:empty?)
end
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class NumberChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class PaysChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class PhoneChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,9 @@
module Types::Champs::Descriptor
class PieceJustificativeChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
field :file_template, Types::File, "Modèle de la pièce justificative.", null: true, extensions: [
{ Extensions::Attachment => { attachment: :piece_justificative_template, root: :type_de_champ } }
]
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class PoleEmploiChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class RegionChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,11 @@
module Types::Champs::Descriptor
class RepetitionChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
field :champ_descriptors, [Types::ChampDescriptorType], "Description des champs dun bloc répétable.", null: true
def champ_descriptors
Loaders::Association.for(object.class, revision_types_de_champ: :type_de_champ).load(object)
end
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class RNAChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class SiretChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class TextChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class TextareaChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class TitreIdentiteChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end

View file

@ -0,0 +1,5 @@
module Types::Champs::Descriptor
class YesNoChampDescriptorType < Types::BaseObject
implements Types::ChampDescriptorType
end
end