From 4f83c8daf0cac478f039e666fcf72d46524fca49 Mon Sep 17 00:00:00 2001 From: Bruce Bolt Date: Tue, 31 Dec 2024 08:49:22 +0000 Subject: [PATCH] Add role appointments reverse link to GraphQL edition type This reverse link uses a different link type depending on the parent object. Therefore adding some logic here to select which link type is required. --- app/graphql/types/edition_type.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/graphql/types/edition_type.rb b/app/graphql/types/edition_type.rb index 782eddc5a..bea5265ce 100644 --- a/app/graphql/types/edition_type.rb +++ b/app/graphql/types/edition_type.rb @@ -99,6 +99,18 @@ class EditionLinks < Types::BaseObject reverse_links_field :related_to_step_navs, :pages_related_to_step_nav, [EditionType] reverse_links_field :secondary_to_step_navs, :secondary_to_step_navs, [EditionType] + field :role_appointments, [EditionType] + + def role_appointments + if object.document_type == "role" || object.document_type == "ministerial_role" + dataloader.with(Sources::ReverseLinkedToEditionsSource, parent_object: object) + .load("role") + else + dataloader.with(Sources::ReverseLinkedToEditionsSource, parent_object: object) + .load("person") + end + end + def available_translations Presenters::Queries::AvailableTranslations.by_edition(object) .translations.fetch(:available_translations, [])