From b5dc71e975f8eae4b2970bfe4f6105bd16713188 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 18 Jan 2023 18:05:59 +0100 Subject: [PATCH] fix(graphql): demarche with pj should return schema --- app/graphql/api/v2/stored_query.rb | 3 +++ app/graphql/extensions/attachment.rb | 5 +++-- app/graphql/types/champ_descriptor_type.rb | 2 -- .../api/v2/graphql_controller_stored_queries_spec.rb | 9 +++++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index ab473ae72..fa0527fc4 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -284,6 +284,9 @@ class API::V2::StoredQuery dateDerniereModification dateDepublication dateFermeture + notice { url } + deliberation { url } + cadreJuridiqueUrl service @include(if: $includeService) { ...ServiceFragment } diff --git a/app/graphql/extensions/attachment.rb b/app/graphql/extensions/attachment.rb index 72462da35..d5ebde7c5 100644 --- a/app/graphql/extensions/attachment.rb +++ b/app/graphql/extensions/attachment.rb @@ -24,10 +24,11 @@ module Extensions # This method resolves (as it states) the field itself # (it's the same as defining a method within a type) def resolve(object:, **_rest) + root_instance = object.public_send(root) Loaders::Association.for( - object.public_send(root).class, + root_instance.class, attachment_assoc => :blob - ).load(object.object) + ).load(root_instance) end # This method is called if the result of the `resolve` diff --git a/app/graphql/types/champ_descriptor_type.rb b/app/graphql/types/champ_descriptor_type.rb index dbac1c088..00893fb14 100644 --- a/app/graphql/types/champ_descriptor_type.rb +++ b/app/graphql/types/champ_descriptor_type.rb @@ -108,8 +108,6 @@ module Types end end - private - def type_de_champ object.type_de_champ end diff --git a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb index 37bba16e0..b3a3e0e1c 100644 --- a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb @@ -2,7 +2,8 @@ describe API::V2::GraphqlController do let(:admin) { create(:administrateur) } let(:token) { APIToken.generate(admin)[1] } let(:legacy_token) { APIToken.send(:unpack, token)[:plain_token] } - let(:procedure) { create(:procedure, :published, :for_individual, :with_service, administrateurs: [admin]) } + let(:procedure) { create(:procedure, :published, :for_individual, :with_service, administrateurs: [admin], types_de_champ_public:) } + let(:types_de_champ_public) { [] } let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) } let(:dossier1) { create(:dossier, :en_construction, :with_individual, procedure: procedure, en_construction_at: 1.day.ago) } let(:dossier2) { create(:dossier, :en_construction, :with_individual, :archived, procedure: procedure, en_construction_at: 3.days.ago) } @@ -28,7 +29,6 @@ describe API::V2::GraphqlController do end describe 'ds-query-v2' do - let(:procedure) { create(:procedure, :published, :for_individual, administrateurs: [admin]) } let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) } let(:query_id) { 'ds-query-v2' } @@ -115,11 +115,12 @@ describe API::V2::GraphqlController do end end - context 'getDemarcheDescriptor' do + context 'getDemarcheDescriptor', vcr: { cassette_name: 'api_geo_regions' } do let(:operation_name) { 'getDemarcheDescriptor' } + let(:types_de_champ_public) { [{ type: :text }, { type: :piece_justificative }, { type: :regions }] } context 'find by number' do - let(:variables) { { demarche: { number: procedure.id } } } + let(:variables) { { demarche: { number: procedure.id }, includeRevision: true } } it { expect(gql_errors).to be_nil