Skip to content

Commit

Permalink
Merge pull request #3115 from alphagov/reduce-graphql-queries
Browse files Browse the repository at this point in the history
Only retrieve change history from database if needed
  • Loading branch information
brucebolt authored Jan 30, 2025
2 parents af13473 + 2b50e3b commit 559fd0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/graphql/types/edition_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class WhipOrganisation < Types::BaseObject

field :body, String
field :brand, String
field :change_history, GraphQL::Types::JSON
field :change_history, GraphQL::Types::JSON, extras: [:parent]
field :current, Boolean
field :default_news_image, Image
field :display_date, GraphQL::Types::ISO8601DateTime
Expand All @@ -158,6 +158,7 @@ class WhipOrganisation < Types::BaseObject
field :active, Boolean, null: false
field :analytics_identifier, String
field :base_path, String
field :change_history, GraphQL::Types::JSON
field :content_id, ID
field :current, Boolean
field :description, String
Expand Down Expand Up @@ -186,11 +187,15 @@ class WhipOrganisation < Types::BaseObject
field :web_url, String
field :withdrawn_notice, WithdrawnNotice

def change_history
Presenters::ChangeHistoryPresenter.new(object).change_history
end

def details
Presenters::ContentTypeResolver.new("text/html").resolve(
Presenters::DetailsPresenter.new(
object.details,
Presenters::ChangeHistoryPresenter.new(object),
nil,
Presenters::ContentEmbedPresenter.new(object),
).details,
)
Expand Down
3 changes: 3 additions & 0 deletions spec/integration/graphql/news_article_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
document_type: "news_story",
details: {
body: "Some text",
change_history: [{ note: "Info", public_timestamp: "2025-01-01 00:01:00" }],
},
)

Expand Down Expand Up @@ -94,6 +95,7 @@
title
details {
body
change_history
}
links {
available_translations {
Expand Down Expand Up @@ -147,6 +149,7 @@
base_path: @edition.base_path,
details: {
body: @edition.details[:body],
change_history: [{ note: "Info", public_timestamp: "2025-01-01 00:01:00" }],
},
links: {
available_translations: [
Expand Down

0 comments on commit 559fd0a

Please sign in to comment.