-
Notifications
You must be signed in to change notification settings - Fork 16
[PP-7469] Support draft content in GraphQL #3908
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
base: main
Are you sure you want to change the base?
Changes from all commits
6964076
b544f9c
a7186c1
32ceaab
914bea8
a9bd65c
082d71a
fab1bf7
e2564c9
bed1e96
c7c2a03
733b5d7
388789d
2399481
014d670
02b9372
1d4d6bb
3e8b3ea
8862626
4577adf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,52 @@ class GraphqlController < ApplicationController | |
| DEFAULT_TTL = ENV.fetch("DEFAULT_TTL", 5.minutes).to_i.seconds | ||
| MINIMUM_TTL = [DEFAULT_TTL, 5.seconds].min | ||
|
|
||
| def draft_content | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the argument in the commit message for having the duplication here, but I do wonder if there's potential for deviation from each other in the future? Given there's only (as far as I can see) two lines difference between live and draft, would DRY-ing up these methods (with some conditional logic for the two lines that are different) be a better approach? |
||
| execute_in_read_replica do | ||
| begin | ||
| encoded_base_path = Addressable::URI.encode("/#{params[:base_path]}") | ||
| edition = EditionFinderService.new(encoded_base_path, with_drafts: true).find | ||
| set_cache_headers(edition) | ||
| return head :not_found unless edition | ||
|
|
||
| if edition.base_path != encoded_base_path | ||
| return redirect_to graphql_draft_content_path(base_path: edition.base_path.gsub(/^\//, "")), status: :see_other | ||
| end | ||
|
|
||
| begin | ||
| query = File.read(Rails.root.join("app/graphql/queries/#{edition.schema_name}.graphql")) | ||
| rescue Errno::ENOENT | ||
| return head :not_found | ||
| end | ||
|
|
||
| result = PublishingApiSchema.execute(query, variables: { base_path: encoded_base_path, with_drafts: true }).to_hash | ||
| report_result(result) | ||
|
|
||
| content_item = GraphqlContentItemService.for_edition(edition).process(result) | ||
|
|
||
| http_status = if content_item["schema_name"] == "gone" && (content_item["details"].nil? || content_item["details"].values.reject(&:blank?).empty?) | ||
| 410 | ||
| else | ||
| 200 | ||
| end | ||
|
|
||
| render json: content_item, status: http_status | ||
| end | ||
| rescue Addressable::URI::InvalidURIError | ||
| Rails.logger.warn "Can't encode request_path '#{params[:base_path]}'" | ||
| return head :bad_request | ||
| rescue StandardError => e | ||
| raise e unless Rails.env.development? | ||
|
|
||
| handle_error_in_development(e) | ||
| end | ||
| end | ||
|
|
||
| def live_content | ||
| execute_in_read_replica do | ||
| begin | ||
| encoded_base_path = Addressable::URI.encode("/#{params[:base_path]}") | ||
| edition = EditionFinderService.new(encoded_base_path, "live").find | ||
| edition = EditionFinderService.new(encoded_base_path).find | ||
| set_cache_headers(edition) | ||
| return head :not_found unless edition | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.