From e19af241cacc30110a4b8c22be97ec511205d499 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 21 Dec 2022 17:42:12 +0100 Subject: [PATCH] feat(graphql): expose pays, region and departement options in schema --- app/graphql/api/v2/stored_query.rb | 18 ++++++++++++++++++ app/graphql/schema.graphql | 12 ++++++------ .../departement_champ_descriptor_type.rb | 6 ++++++ .../descriptor/pays_champ_descriptor_type.rb | 6 ++++++ .../descriptor/region_champ_descriptor_type.rb | 6 ++++++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index 69e3ea59e..ab473ae72 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -346,6 +346,24 @@ class API::V2::StoredQuery collapsibleExplanationEnabled collapsibleExplanationText } + ... on PaysChampDescriptor { + options { + name + code + } + } + ... on RegionChampDescriptor { + options { + name + code + } + } + ... on DepartementChampDescriptor { + options { + name + code + } + } } fragment AvisFragment on Avis { diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index cfb9a396e..1bf7e53f1 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -1094,9 +1094,9 @@ type DepartementChampDescriptor implements ChampDescriptor { label: String! """ - List des options d’un champ avec selection. + List des departements. """ - options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + options: [Departement!] """ Est-ce que le champ est obligatoire ? @@ -3025,9 +3025,9 @@ type PaysChampDescriptor implements ChampDescriptor { label: String! """ - List des options d’un champ avec selection. + List des pays. """ - options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + options: [Pays!] """ Est-ce que le champ est obligatoire ? @@ -3313,9 +3313,9 @@ type RegionChampDescriptor implements ChampDescriptor { label: String! """ - List des options d’un champ avec selection. + List des regions. """ - options: [String!] @deprecated(reason: "Utilisez le champ `DropDownListChampDescriptor.options` à la place.") + options: [Region!] """ Est-ce que le champ est obligatoire ? diff --git a/app/graphql/types/champs/descriptor/departement_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/departement_champ_descriptor_type.rb index f61dbc235..f1fac4ff9 100644 --- a/app/graphql/types/champs/descriptor/departement_champ_descriptor_type.rb +++ b/app/graphql/types/champs/descriptor/departement_champ_descriptor_type.rb @@ -1,5 +1,11 @@ module Types::Champs::Descriptor class DepartementChampDescriptorType < Types::BaseObject implements Types::ChampDescriptorType + + field :options, [Types::Champs::DepartementChampType::DepartementType], "List des departements.", null: true + + def options + APIGeoService.departements + end end end diff --git a/app/graphql/types/champs/descriptor/pays_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/pays_champ_descriptor_type.rb index 7dbeab097..0da7b47a3 100644 --- a/app/graphql/types/champs/descriptor/pays_champ_descriptor_type.rb +++ b/app/graphql/types/champs/descriptor/pays_champ_descriptor_type.rb @@ -1,5 +1,11 @@ module Types::Champs::Descriptor class PaysChampDescriptorType < Types::BaseObject implements Types::ChampDescriptorType + + field :options, [Types::Champs::PaysChampType::PaysType], "List des pays.", null: true + + def options + APIGeoService.countries + end end end diff --git a/app/graphql/types/champs/descriptor/region_champ_descriptor_type.rb b/app/graphql/types/champs/descriptor/region_champ_descriptor_type.rb index 4e5c2e32f..0adf119ac 100644 --- a/app/graphql/types/champs/descriptor/region_champ_descriptor_type.rb +++ b/app/graphql/types/champs/descriptor/region_champ_descriptor_type.rb @@ -1,5 +1,11 @@ module Types::Champs::Descriptor class RegionChampDescriptorType < Types::BaseObject implements Types::ChampDescriptorType + + field :options, [Types::Champs::RegionChampType::RegionType], "List des regions.", null: true + + def options + APIGeoService.regions + end end end