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

Render news articles using GraphQL #3447

Merged
merged 2 commits into from
Dec 23, 2024
Merged

Render news articles using GraphQL #3447

merged 2 commits into from
Dec 23, 2024

Conversation

brucebolt
Copy link
Member

@brucebolt brucebolt commented Nov 28, 2024

This switches the rendering of news articles to use Publishing API's GraphQL endpoint, only when the feature flag is enabled.

The code here (and in the associated Publishing API PR: alphagov/publishing-api#3008) has been written in such a way that the least number of changes have been needed in this app, as this is only a proof of concept for now. If we decide to use GraphQL for everything going forward, we should revisit the structure of content returned by GraphQL.

Also note that GraphQL powered queries rely on an initial request to Content Store, since we need to know the content type before deciding whether to use GraphQL.

Furthermore it only renders one level of parent taxon. We will have follow-up work to change how the taxonomy is presented by GraphQL, as it's recursive nature doesn't fit the current implementation.

Trello card

@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 November 28, 2024 16:28 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from d94dad1 to 515a0aa Compare November 28, 2024 16:30
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 November 28, 2024 16:30 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 515a0aa to 4896c26 Compare November 28, 2024 16:37
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 November 28, 2024 16:38 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 4896c26 to d83bd0c Compare November 28, 2024 17:20
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 November 28, 2024 17:20 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from d83bd0c to 999d3c2 Compare November 28, 2024 17:22
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 November 28, 2024 17:22 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 999d3c2 to 2f9cecf Compare November 29, 2024 11:55
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 November 29, 2024 11:55 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 2f9cecf to d77199c Compare November 29, 2024 12:16
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 November 29, 2024 12:16 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from d77199c to 9f0abcb Compare November 29, 2024 12:53
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 November 29, 2024 12:54 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 9f0abcb to 1f97173 Compare December 2, 2024 11:51
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 December 2, 2024 11:52 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 1f97173 to f5d1bb1 Compare December 2, 2024 16:23
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 December 2, 2024 16:24 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from f5d1bb1 to 5983a10 Compare December 2, 2024 16:24
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 December 2, 2024 16:24 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 5983a10 to 7399d93 Compare December 2, 2024 17:21
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 December 2, 2024 17:22 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 7399d93 to 9e25802 Compare December 3, 2024 08:06
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 3, 2024 08:06 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 9e25802 to 442f3d2 Compare December 3, 2024 08:07
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 3, 2024 08:07 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 442f3d2 to 10ae11c Compare December 3, 2024 11:51
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 3, 2024 11:51 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 10ae11c to 3d92bba Compare December 3, 2024 11:53
@govuk-ci govuk-ci had a problem deploying to government-frontend-pr-3447 December 16, 2024 13:21 Failure
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 8bbf5f4 to 6888f79 Compare December 16, 2024 13:37
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 16, 2024 13:37 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 6888f79 to b8437e8 Compare December 16, 2024 13:39
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 16, 2024 13:39 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from b8437e8 to 7a02425 Compare December 16, 2024 13:40
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 16, 2024 13:40 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 7a02425 to 04a1b56 Compare December 18, 2024 10:22
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 18, 2024 10:22 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 04a1b56 to f5b7ecd Compare December 18, 2024 12:58
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 18, 2024 12:58 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from f5b7ecd to a9da5b1 Compare December 18, 2024 13:12
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 18, 2024 13:12 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from a9da5b1 to eb06e37 Compare December 18, 2024 13:40
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 18, 2024 13:41 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from eb06e37 to ea1da19 Compare December 18, 2024 13:47
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 18, 2024 13:47 Inactive
@brucebolt brucebolt force-pushed the graphql-news-articles branch from ea1da19 to c36541a Compare December 18, 2024 14:21
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 18, 2024 14:21 Inactive
Comment on lines 140 to 155
@content_item = if use_graphql?
schema_name_result = Services
.publishing_api
.graphql_content_item(Graphql::SchemaNameQuery.new(content_item_path).query)

if schema_name_result["schema_name"] == "news_article"
load_content_item_from_graphql
else
load_content_item_from_content_store
end
else
load_content_item_from_content_store
end
Copy link
Member

Choose a reason for hiding this comment

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

thought: two requests issue

I suppose if we were to switch over to GraphQL for everything, we might be able to remove the schema name query and do what I suggested in the meeting with Richard and Martyn: have a single big query that specifies what we want for each type using the ...Type syntax. We'd have to weigh up whether one big query is better than one very small one and then the normal schema-specific one

I think this could work with both the current more strongly typed implementation and the Edition god type alternative. With the latter, we could have types that don't themselves define any fields but do at least map document types to GraphQL types, like you've already done for news articles: https://github.com/alphagov/publishing-api/blob/main/app/graphql/types/news_article_type.rb. Then whichever ...Type section of the query matches would be executed

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be gross to change this to just be

 @content_item = use_graphql? ? load_content_item_from_graphql : load_content_item_from_content_store

and then at the top of the load_content_item_from_graphql method we call a new method that checks for the content type and either carries on using graphql or just returns load_content_item_from_content_store

I know that it hides a bit of functionality but it would make this bit of code look nicer

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reduced this down to one GraphQL query now. We'll need to think about the query a bit more once any changes to the typing in Publishing API have been made and when we add GraphQL support for further document types rendered by Government Frontend.

This allows us to toggle the use of GraphQL by environment, in the same
way as Collections: alphagov/collections@bc1fedf.
@brucebolt brucebolt force-pushed the graphql-news-articles branch from c36541a to 90f8d4d Compare December 23, 2024 08:39
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 23, 2024 08:39 Inactive
This retrieves the content from Publishing API, instead of Content
Store, using a GraphQL query.

Note this has been done in the way that reduces the number of changes
needed in this application.
@brucebolt brucebolt force-pushed the graphql-news-articles branch from 90f8d4d to 3f85edc Compare December 23, 2024 08:49
@govuk-ci govuk-ci temporarily deployed to government-frontend-pr-3447 December 23, 2024 08:50 Inactive
Copy link
Contributor

@JonathanHallam JonathanHallam left a comment

Choose a reason for hiding this comment

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

Thanks Bruce

Copy link
Contributor

@catalinailie catalinailie left a comment

Choose a reason for hiding this comment

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

Looks good to me

@brucebolt brucebolt merged commit 582359c into main Dec 23, 2024
11 checks passed
@brucebolt brucebolt deleted the graphql-news-articles branch December 23, 2024 15:27
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.

6 participants