Skip to content

Commit

Permalink
Add role appointments reverse link to GraphQL edition type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brucebolt committed Dec 31, 2024
1 parent e981e54 commit 4f83c8d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/graphql/types/edition_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
Expand Down

0 comments on commit 4f83c8d

Please sign in to comment.