-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: main
Are you sure you want to change the base?
Conversation
4f83c8d
to
b6b3749
Compare
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.
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.
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.
b6b3749
to
213b539
Compare
There was a problem hiding this 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 👍
all_links = @object | ||
.document | ||
.reverse_links |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
target_document = create(:edition) | ||
source_document_1 = create(:edition) | ||
source_document_2 = create(:edition) | ||
source_document_3 = create(:edition) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
213b539
to
e3b484b
Compare
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