Skip to content

Commit 0d57f2c

Browse files
Gweatonyndajas
andcommitted
Add additional edition type fields
This expands the edition type to include all the top-level properties that a content item contains, and most of the nested data. The queries sent by frontend apps will be able to pare down the data that gets sent to them from the Publishing API, but we are able to get almost all the same data as presented by the current content item if required Some fields are not yet fully implemented: - `withdrawn_notice` is currently just a nullable String, but will be implemented more fully in an upcoming commit - `details` is currently a generic JSON type as it's an inherently flexible object that could have a wide range of fields. It may be worth defining more specific types and moving the `details` keys up to the top level on each type for each page being built in future. This would allow for reduced complexity in querying the required fields. We've used JSON to keep it flexible and to allow consumers to fall back on these fields if they need to. - `links` needs further work to query and present the data that is currently presented in the content item, so we've left the field off for now, rather than adding a non-so-useful placeholder. We'll need to add links when we add pages that use links like the ministers index page. It would be good to figure out how we can reduce the need for full link expansion and move to a more minimal on-demand version when we tackle this piece of work. - `publishing_scheduled_at` and `scheduled_publishing_delay_seconds` are not currently available in Publishing API. They are generated in Content Store, so we just return `null` here. If we do need to serve these in future, we'd need to find a way of storing these in Publishing API, but that's definitely out of scope for now. Co-authored-by: Ynda Jas <[email protected]>
1 parent 887ab19 commit 0d57f2c

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

app/graphql/types/edition_type.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
module Types
44
class EditionType < Types::BaseObject
5-
field :title, String
5+
field :analytics_identifier, String
6+
field :base_path, String
7+
field :content_id, ID
8+
field :description, String
9+
field :details, GraphQL::Types::JSON, null: false
10+
field :document_type, String
11+
field :first_published_at, GraphQL::Types::ISO8601DateTime, null: false
12+
field :locale, String, null: false
13+
field :phase, String, null: false
14+
field :public_updated_at, GraphQL::Types::ISO8601DateTime, null: false
15+
field :publishing_app, String
16+
field :publishing_request_id, String
17+
field :publishing_scheduled_at, GraphQL::Types::ISO8601DateTime
18+
field :rendering_app, String
19+
field :scheduled_publishing_delay_seconds, Int
20+
field :schema_name, String
21+
field :title, String, null: false
22+
field :updated_at, GraphQL::Types::ISO8601DateTime
23+
field :withdrawn_notice, String
24+
25+
# Aliased by field methods for fields that are currently presented in the
26+
# content item, but come from Content Store, so we can't provide them here
27+
def not_stored_in_publishing_api
28+
nil
29+
end
30+
31+
alias_method :publishing_scheduled_at, :not_stored_in_publishing_api
32+
alias_method :scheduled_publishing_delay_seconds, :not_stored_in_publishing_api
633
end
734
end

spec/integration/graphql_spec.rb

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
RSpec.describe "GraphQL" do
22
describe "generic edition" do
33
before do
4-
create(:live_edition, title: "My Generic Edition", base_path: "/my/generic/edition")
4+
document = create(:document, content_id: "d53db33f-d4ac-4eb3-839a-d415174eb906")
5+
@edition = create(:live_edition, document:, base_path: "/my/generic/edition")
56
end
67

78
it "exposes generic edition fields" do
@@ -11,6 +12,27 @@
1112
edition(basePath: \"/my/generic/edition\") {
1213
... on Edition {
1314
title
15+
analyticsIdentifier
16+
basePath
17+
contentId
18+
description
19+
details
20+
documentType
21+
firstPublishedAt
22+
locale
23+
phase
24+
publicUpdatedAt
25+
publishingApp
26+
publishingRequestId
27+
publishingScheduledAt
28+
renderingApp
29+
scheduledPublishingDelaySeconds
30+
schemaName
31+
updatedAt
32+
withdrawnNotice {
33+
explanation
34+
withdrawnAt
35+
}
1436
}
1537
}
1638
}",
@@ -19,12 +41,35 @@
1941
expected = {
2042
"data": {
2143
"edition": {
22-
"title": "My Generic Edition",
44+
"analyticsIdentifier": @edition.analytics_identifier,
45+
"basePath": @edition.base_path,
46+
"contentId": @edition.content_id,
47+
"description": @edition.description,
48+
"details": @edition.details,
49+
"documentType": @edition.document_type,
50+
"firstPublishedAt": @edition.first_published_at.iso8601,
51+
"locale": @edition.locale,
52+
"phase": @edition.phase,
53+
"publicUpdatedAt": @edition.public_updated_at.iso8601,
54+
"publishingApp": @edition.publishing_app,
55+
"publishingRequestId": @edition.publishing_request_id,
56+
"publishingScheduledAt": nil,
57+
"renderingApp": @edition.rendering_app,
58+
"scheduledPublishingDelaySeconds": nil,
59+
"schemaName": @edition.schema_name,
60+
"title": @edition.title,
61+
"updatedAt": @edition.updated_at.iso8601,
62+
"withdrawnNotice": {
63+
"explanation": nil,
64+
"withdrawnAt": nil,
65+
},
2366
},
2467
},
25-
}.to_json
68+
}
2669

27-
expect(response.body).to eq(expected)
70+
parsed_response = JSON.parse(response.body).deep_symbolize_keys
71+
72+
expect(parsed_response).to eq(expected)
2873
end
2974

3075
it "does not expose non-generic edition fields" do

0 commit comments

Comments
 (0)