Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an edition type for all GraphQL edition-like documents #3063

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

brucebolt
Copy link
Member

@brucebolt brucebolt commented Dec 30, 2024

This moves all edition types into a single type, to reduce duplication and minimise the amount of code required when adding support for content types to GraphQL.

The bespoke code for getting role_appointments on the ministers index page has been retained, as this was added to improve performance for that page due to the number of links and their complexity.

When we want to add a new content type that doesn't need any bespoke code, we just need to ensure all the relevant details fields are present in the Edition type. All the link types have already been added and any links can be requested for any document type. Without making the changes in this PR, we would need to create a new type for each document type, which would include a lot of code duplication where similar things exist across the types.

Also adds support for edition links and multi-level edition links.

Trello card

@brucebolt brucebolt force-pushed the flatten-graphql-edition branch 10 times, most recently from 4f83c8d to b6b3749 Compare December 31, 2024 08:53
brucebolt added a commit to alphagov/government-frontend that referenced this pull request Dec 31, 2024
Publishing API was updated in
alphagov/publishing-api#3063 to have a single
edition type for most content, instead of a specific type for news
articles.

Updating the query used by this application in making such requests to
Publishing API.
brucebolt added a commit to alphagov/collections that referenced this pull request Dec 31, 2024
Publishing API was updated in
alphagov/publishing-api#3063 to have a single
edition type for most content, instead of a specific type for roles.

Updating the query used by this application in making such requests to
Publishing API.
brucebolt added a commit to alphagov/collections that referenced this pull request Dec 31, 2024
Publishing API was updated in
alphagov/publishing-api#3063 to have a single
edition type for most content, instead of a specific type for the world
index page.

Updating the query used by this application in making such requests to
Publishing API.
@brucebolt brucebolt changed the title Implement one big edition type for all GraphQL edition-like documents Implement an edition type for all GraphQL edition-like documents Dec 31, 2024
@brucebolt brucebolt force-pushed the flatten-graphql-edition branch from b6b3749 to 213b539 Compare December 31, 2024 13:34
@brucebolt brucebolt marked this pull request as ready for review December 31, 2024 15:44
Copy link
Contributor

@mike3985 mike3985 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does look pretty good overall 👍

Comment on lines +11 to +13
all_links = @object
.document
.reverse_links
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing some eager loading here?

  .reverse_links
  .includes(source_documents: @content_store)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've added that in and it's substantially reduced the number of queries being made.

Comment on lines 3 to 6
target_document = create(:edition)
source_document_1 = create(:edition)
source_document_2 = create(:edition)
source_document_3 = create(:edition)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be easier on my brain if these were called "source_edition"s

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll update the existing spec too.


edition_links = Link
.where(target_content_id: @object.content_id, link_type: link_types)
.where.not(edition: nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never worked with edition links. To me it looks like the first Active Record query ("link_set_links = ...") would return both link set links and edition links. Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. I haven't noticed that the reverse_links relationship didn't involve LinkSet in any way. I'll update this to just do the one query then grab the edition differently depending on the link type.

These are editions, not documents, so should be named as such to avoid
confusion.
This allows us to define reverse links on a type in a generic way, in
the same format as direct links.
This allows us to return the direct edition links for editions using
GraphQL.

Also means we can now support multi-level edition links, which is
currently not possible using the content item version of editions.
This allows us to return the reverse edition links for editions using
GraphQL.
This removes the hardcoding and duplication amongst the varieties of
Edition we have currently implemented.

These changes will make it easier to implement new document types, as
the fields and links have already been defined.

Since all links are now returned as the Edition type, any field can be
selected from them, not just those that have been defined in the link
type. This makes queries much more flexible, as the frontend application
can request any fields it likes from the links, without any changes
being made in Publishing API.

The Minister Index Type is being retained, since that contains custom
optimisations specific to the links on that page. In future, it may be
possible to decouple that type from editions entirely, meaning we
wouldn't need to ever publish that page from Whitehall.

Note 1: this requires selection of all fields within `details` for any
edition. Previously this was only required when `details` was nested
within a link, making it consistent whether the edition is returned at
the top-level or as a link.

Note 2: role appointment reverse links will be added in a separate
commit, as they require some logic.
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.
@brucebolt brucebolt force-pushed the flatten-graphql-edition branch from 213b539 to e3b484b Compare January 2, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants