Skip to content

Commit 858148e

Browse files
Gweatonyndajas
andcommitted
WIP add additional edition types
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 - `links` needs further work to present the data that is currently presented in the content item - `publishing_scheduled_at` and `scheduled_publishing_delay_seconds` are not currently available in Publishing API, so they just return `null`. This is what they currently return for `/world` anyway, but for other pages, we might need to explore how to retrieve these data if needed Co-authored-by: Ynda Jas <[email protected]>
1 parent e40d9aa commit 858148e

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

app/graphql/types/edition_type.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@
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+
# TODO: make details a more realistic type
10+
field :details, String, null: false
11+
field :document_type, String
12+
field :first_published_at, GraphQL::Types::ISO8601DateTime, null: false
13+
# TODO: work out how to retrieve the links returned in the content item
14+
field :links, [String], null: false
15+
field :locale, String, null: false
16+
field :phase, String, null: false
17+
field :public_updated_at, GraphQL::Types::ISO8601DateTime, null: false
18+
field :publishing_app, String
19+
field :publishing_request_id, String
20+
field :publishing_scheduled_at, GraphQL::Types::ISO8601DateTime
21+
field :rendering_app, String
22+
field :scheduled_publishing_delay_seconds, Int
23+
field :schema_name, String
24+
field :title, String, null: false
25+
field :updated_at, GraphQL::Types::ISO8601DateTime
26+
field :withdrawn_notice, String
27+
28+
# Aliased by field methods for fields that are currently presented in the
29+
# content item, but are not available via the Publishing API.
30+
def not_stored_in_publishing_api
31+
nil
32+
end
33+
34+
alias_method :publishing_scheduled_at, :not_stored_in_publishing_api
35+
alias_method :scheduled_publishing_delay_seconds, :not_stored_in_publishing_api
636
end
737
end

spec/integration/graphql_spec.rb

Lines changed: 51 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,28 @@
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+
links
23+
locale
24+
phase
25+
publicUpdatedAt
26+
publishingApp
27+
publishingRequestId
28+
publishingScheduledAt
29+
renderingApp
30+
scheduledPublishingDelaySeconds
31+
schemaName
32+
updatedAt
33+
withdrawnNotice {
34+
explanation
35+
withdrawnAt
36+
}
1437
}
1538
}
1639
}",
@@ -19,12 +42,36 @@
1942
expected = {
2043
"data": {
2144
"edition": {
22-
"title": "My Generic Edition",
45+
"analyticsIdentifier": @edition.analytics_identifier,
46+
"basePath": @edition.base_path,
47+
"contentId": @edition.content_id,
48+
"description": @edition.description,
49+
"details": @edition.details.to_s,
50+
"documentType": @edition.document_type,
51+
"firstPublishedAt": @edition.first_published_at.iso8601,
52+
"links": [],
53+
"locale": @edition.locale,
54+
"phase": @edition.phase,
55+
"publicUpdatedAt": @edition.public_updated_at.iso8601,
56+
"publishingApp": @edition.publishing_app,
57+
"publishingRequestId": @edition.publishing_request_id,
58+
"publishingScheduledAt": nil,
59+
"renderingApp": @edition.rendering_app,
60+
"scheduledPublishingDelaySeconds": nil,
61+
"schemaName": @edition.schema_name,
62+
"title": @edition.title,
63+
"updatedAt": @edition.updated_at.iso8601,
64+
"withdrawnNotice": {
65+
"explanation": nil,
66+
"withdrawnAt": nil,
67+
},
2368
},
2469
},
25-
}.to_json
70+
}
2671

27-
expect(response.body).to eq(expected)
72+
parsed_response = JSON.parse(response.body).deep_symbolize_keys
73+
74+
expect(parsed_response).to eq(expected)
2875
end
2976

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

0 commit comments

Comments
 (0)