-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for news articles to GraphQL endpoint #3008
Changes from all commits
f71ccd1
a9d1821
c1d8d5e
a2841e1
9b2699f
d4cc096
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
class NewsArticleType < Types::EditionType | ||
def self.document_types = %w[ | ||
government_response | ||
news_story | ||
press_release | ||
world_news_story | ||
] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ module Types | |
class QueryType < Types::BaseObject | ||
field :edition, EditionTypeOrSubtype, description: "An edition or one of its subtypes" do | ||
argument :base_path, String | ||
argument :content_store, String, required: false, default_value: "live" | ||
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. question: interface
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. Well, we're gonna have to face this decision at some point! I wonder if there's already a Content Store-free name for this concept in use? |
||
end | ||
|
||
def edition(base_path:) | ||
Edition.live.find_by(base_path:) | ||
def edition(base_path:, content_store:) | ||
Edition.where(content_store:).find_by(base_path:) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
RSpec.describe Types::NewsArticleType do | ||
describe ".document_types" do | ||
it "defines the document types for .resolve_type to distinguish the type from the generic Edition type" do | ||
expect(described_class.document_types).to eq(%w[ | ||
government_response | ||
news_story | ||
press_release | ||
world_news_story | ||
]) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
RSpec.describe Types::QueryType do | ||
include GraphQL::Testing::Helpers.for(PublishingApiSchema) | ||
|
||
describe "#edition" do | ||
let(:query) do | ||
<<~QUERY | ||
query($basePath: String!, $contentStore: String!) { | ||
edition(basePath: $basePath, contentStore: $contentStore) { | ||
... on Edition { | ||
basePath | ||
state | ||
} | ||
} | ||
} | ||
QUERY | ||
end | ||
|
||
context "when there is only a draft edition" do | ||
let(:draft_edition) { create(:draft_edition) } | ||
|
||
context "requesting the draft edition" do | ||
it "returns the draft edition" do | ||
expected_data = { | ||
"basePath" => draft_edition.base_path, | ||
"state" => "draft", | ||
} | ||
|
||
result = PublishingApiSchema.execute(query, variables: { basePath: draft_edition.base_path, contentStore: "draft" }) | ||
edition_data = result.dig("data", "edition") | ||
expect(edition_data).to eq(expected_data) | ||
end | ||
end | ||
|
||
context "requesting the live edition" do | ||
it "returns no edition" do | ||
result = PublishingApiSchema.execute(query, variables: { basePath: draft_edition.base_path, contentStore: "live" }) | ||
edition_data = result.dig("data", "edition") | ||
expect(edition_data).to be_nil | ||
end | ||
end | ||
end | ||
|
||
context "when there is only a live edition" do | ||
let(:live_edition) { create(:live_edition) } | ||
|
||
context "requesting the draft edition" do | ||
it "returns no edition" do | ||
result = PublishingApiSchema.execute(query, variables: { basePath: live_edition.base_path, contentStore: "draft" }) | ||
edition_data = result.dig("data", "edition") | ||
expect(edition_data).to be_nil | ||
end | ||
end | ||
|
||
context "requesting the live edition" do | ||
it "returns the live edition" do | ||
expected_data = { | ||
"basePath" => live_edition.base_path, | ||
"state" => "published", | ||
} | ||
|
||
result = PublishingApiSchema.execute(query, variables: { basePath: live_edition.base_path, contentStore: "live" }) | ||
edition_data = result.dig("data", "edition") | ||
expect(edition_data).to eq(expected_data) | ||
end | ||
end | ||
end | ||
|
||
context "when there is a published edition and a newer draft edition" do | ||
let(:document) { create(:document) } | ||
let(:base_path) { "/foo" } | ||
let!(:live_edition) { create(:live_edition, document:, base_path:, user_facing_version: 1) } | ||
let!(:draft_edition) { create(:draft_edition, document:, base_path:, user_facing_version: 2) } | ||
|
||
context "requesting the draft edition" do | ||
it "returns the draft edition" do | ||
expected_data = { | ||
"basePath" => draft_edition.base_path, | ||
"state" => "draft", | ||
} | ||
|
||
result = PublishingApiSchema.execute(query, variables: { basePath: draft_edition.base_path, contentStore: "draft" }) | ||
edition_data = result.dig("data", "edition") | ||
expect(edition_data).to eq(expected_data) | ||
end | ||
end | ||
|
||
context "requesting the live edition" do | ||
it "returns the live edition" do | ||
expected_data = { | ||
"basePath" => live_edition.base_path, | ||
"state" => "published", | ||
} | ||
|
||
result = PublishingApiSchema.execute(query, variables: { basePath: live_edition.base_path, contentStore: "live" }) | ||
edition_data = result.dig("data", "edition") | ||
expect(edition_data).to eq(expected_data) | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
RSpec.describe "Types::WorldIndexType" do | ||
describe ".document_type" do | ||
it "defines a document type for .resolve_type to distinguish the type from the generic Edition type" do | ||
expect(Types::WorldIndexType.document_type).to eq("world_index") | ||
describe ".document_types" do | ||
it "defines the document types for .resolve_type to distinguish the type from the generic Edition type" do | ||
expect(Types::WorldIndexType.document_types).to eq(%w[world_index]) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: approach
Given the lack of type-specific fields, I'm curious if there's a benefit to this versus just falling back to the generic
EditionType