Skip to content

Commit

Permalink
WIP: get this app using GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
brucebolt committed Nov 28, 2024
1 parent dde0c86 commit d94dad1
Showing 1 changed file with 55 additions and 7 deletions.
62 changes: 55 additions & 7 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,64 @@ def set_guide_draft_access_token
@content_item.draft_access_token = params[:token]
end

def graphql_query(base_path)
<<-QUERY
{
edition(basePath: "#{base_path}", contentStore: "live") {
... on NewsArticle {
basePath
title
schemaName
details
documentType
}
}
}
QUERY
end

## This is a hack to stop us needing to rewrite most of this application to support the format for GraphQL responses
class GdsApi::Response
def update_response_body
puts @http_response.inspect

Check failure on line 158 in app/controllers/content_items_controller.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Rails/Output: Do not write to stdout. Use Rails's logger if you want to log.
updated_response = JSON.parse(@http_response.body).dig("data", "edition").deep_transform_keys(&:underscore)
@http_response = RestClient::Response.create(
updated_response.to_json,
@http_response.net_http_res,
@http_response.request,
)
end
end

def load_content_item
content_item = Services.content_store.content_item(content_item_path)
# # TODO: add the feature flag here
if params.include?(:graphql)
content_item = Services
.publishing_api
.graphql_query(graphql_query(content_item_path))
# .dig("data", "edition")
# .deep_transform_keys(&:underscore)

content_item.update_response_body

puts content_item.inspect

Check failure on line 179 in app/controllers/content_items_controller.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Rails/Output: Do not write to stdout. Use Rails's logger if you want to log.

@content_item = PresenterBuilder.new(

Check failure on line 181 in app/controllers/content_items_controller.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/IdenticalConditionalBranches: Move `@content_item = PresenterBuilder.new( content_item, content_item_path, view_context, ).presenter` out of the conditional.
content_item,
content_item_path,
view_context,
).presenter
else
content_item = Services.content_store.content_item(content_item_path)

content_item["links"]["ordered_related_items"] = ordered_related_items(content_item["links"]) if content_item["links"]
content_item["links"]["ordered_related_items"] = ordered_related_items(content_item["links"]) if content_item["links"]

@content_item = PresenterBuilder.new(
content_item,
content_item_path,
view_context,
).presenter
@content_item = PresenterBuilder.new(

Check failure on line 191 in app/controllers/content_items_controller.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/IdenticalConditionalBranches: Move `@content_item = PresenterBuilder.new( content_item, content_item_path, view_context, ).presenter` out of the conditional.
content_item,
content_item_path,
view_context,
).presenter
end
end

def ordered_related_items(links)
Expand Down

0 comments on commit d94dad1

Please sign in to comment.