Skip to content

Commit

Permalink
Merge pull request #3500 from alphagov/update-graphql-queries
Browse files Browse the repository at this point in the history
Update GraphQL query to use generic edition type
  • Loading branch information
brucebolt authored Jan 10, 2025
2 parents 449d130 + 96590a1 commit 745730a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def load_content_item
@content_item = if use_graphql?
graphql_response = Services
.publishing_api
.graphql_content_item(Graphql::NewsArticleQuery.new(content_item_path).query)
.graphql_content_item(Graphql::EditionQuery.new(content_item_path).query)

if graphql_response["schema_name"] == "news_article"
PresenterBuilder.new(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Graphql::NewsArticleQuery
class Graphql::EditionQuery
def initialize(base_path)
@base_path = base_path
end
Expand All @@ -10,10 +10,25 @@ def query
base_path: "#{@base_path}",
content_store: "live",
) {
... on NewsArticle {
... on Edition {
base_path
description
details
details {
body
change_history
default_news_image {
alt_text
url
}
display_date
emphasised_organisations
first_public_at
image {
alt_text
url
}
political
}
document_type
first_published_at
links {
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ class ContentItemsControllerTest < ActionController::TestCase
base_path = "content-item"

graphql_fixture = fetch_graphql_fixture("news_article")
stub_publishing_api_graphql_content_item(Graphql::NewsArticleQuery.new("/#{base_path}").query, graphql_fixture)
stub_publishing_api_graphql_content_item(Graphql::EditionQuery.new("/#{base_path}").query, graphql_fixture)

get :show,
params: {
path: base_path,
}

assert_requested :post, "#{PUBLISHING_API_ENDPOINT}/graphql",
body: { query: Graphql::NewsArticleQuery.new("/#{base_path}").query },
body: { query: Graphql::EditionQuery.new("/#{base_path}").query },
times: 1

assert_not_requested :get, "#{content_store_endpoint}/content/#{base_path}"
Expand All @@ -134,15 +134,15 @@ class ContentItemsControllerTest < ActionController::TestCase

graphql_fixture = fetch_graphql_fixture("news_article")
graphql_fixture["data"]["edition"]["schema_name"] = "case_study"
stub_publishing_api_graphql_content_item(Graphql::NewsArticleQuery.new("/#{base_path}").query, graphql_fixture)
stub_publishing_api_graphql_content_item(Graphql::EditionQuery.new("/#{base_path}").query, graphql_fixture)

get :show,
params: {
path: path_for(content_item),
}

assert_requested :post, "#{PUBLISHING_API_ENDPOINT}/graphql",
body: { query: Graphql::NewsArticleQuery.new("/#{base_path}").query }
body: { query: Graphql::EditionQuery.new("/#{base_path}").query }

assert_requested :get, "#{content_store_endpoint}/content/#{base_path}",
times: 1
Expand Down

0 comments on commit 745730a

Please sign in to comment.