-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use GraphQL for rendering news articles
This retrieves the content from Publishing API, instead of Content Store, using a GraphQL query. Note this has been done in the way that reduces the number of changes needed in this application. As a result, we have introduced a small "hack" to return the data in `GdsApi::Response` format but with this app rewriting the hash keys to make them all underscore based.
- Loading branch information
Showing
7 changed files
with
272 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
class Graphql::NewsArticleQuery | ||
def initialize(base_path) | ||
@base_path = base_path | ||
end | ||
|
||
def query | ||
<<-QUERY | ||
{ | ||
edition( | ||
basePath: "#{@base_path}", | ||
contentStore: "live", | ||
) { | ||
... on NewsArticle { | ||
basePath | ||
description | ||
details | ||
documentType | ||
firstPublishedAt | ||
links { | ||
availableTranslations { | ||
basePath | ||
locale | ||
} | ||
government { | ||
details { | ||
current | ||
} | ||
title | ||
} | ||
organisations { | ||
basePath | ||
contentId | ||
title | ||
} | ||
people { | ||
basePath | ||
contentId | ||
title | ||
} | ||
taxons { | ||
basePath | ||
contentId | ||
documentType | ||
phase | ||
title | ||
links { | ||
parentTaxons { | ||
basePath | ||
contentId | ||
documentType | ||
phase | ||
title | ||
} | ||
} | ||
} | ||
topicalEvents { | ||
basePath | ||
contentId | ||
title | ||
} | ||
worldLocations { | ||
basePath | ||
contentId | ||
title | ||
} | ||
} | ||
locale | ||
schemaName | ||
title | ||
} | ||
} | ||
} | ||
QUERY | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"data": { | ||
"edition": { | ||
"basePath": "/government/news/announcement", | ||
"description": "Summary of the news", | ||
"details": { | ||
"body": "Some text", | ||
"political": "true" | ||
}, | ||
"documentType": "news_story", | ||
"firstPublishedAt": "2016-12-25T01:02:03+00:00", | ||
"links": { | ||
"availableTranslations": [ | ||
{ | ||
"basePath": "/government/news/announcement", | ||
"locale": "en" | ||
} | ||
], | ||
"government": [ | ||
{ | ||
"details": { | ||
"current": false | ||
}, | ||
"title": "A government" | ||
} | ||
], | ||
"organisations": [ | ||
{ | ||
"basePath": "/organisation-1", | ||
"title": "An organisation" | ||
} | ||
], | ||
"people": [ | ||
{ | ||
"basePath": "/person-1", | ||
"title": "A person" | ||
} | ||
], | ||
"taxons": [ | ||
{ | ||
"basePath": "/taxon-1", | ||
"contentId": "8fa1fa2f-bcce-4cde-98fb-308514c35c63", | ||
"title": "Taxon 1", | ||
"links": { | ||
"parentTaxons": [ | ||
{ | ||
"basePath": "/taxon-2", | ||
"contentId": "9de167ce-6c4f-40b1-a45e-e3160d75556e", | ||
"title": "Taxon 2" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"topicalEvents": [ | ||
{ | ||
"basePath": "/topical-event-1", | ||
"title": "A topical event" | ||
} | ||
], | ||
"worldLocations": [ | ||
{ | ||
"basePath": "/world-location-1", | ||
"title": "A world location" | ||
} | ||
] | ||
}, | ||
"schemaName": "news_article", | ||
"title": "Generic news article" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "presenter_test_helper" | ||
|
||
class NewsArticleGraphqlPresenterTest | ||
class NewsArticleGraphqlPresenterTestCase < GraphqlPresenterTestCase | ||
attr_accessor :example_schema_name | ||
|
||
def schema_name | ||
"news_article" | ||
end | ||
end | ||
|
||
class PresentedNewsArticleGraphqlTest < NewsArticleGraphqlPresenterTestCase | ||
test "presents a description" do | ||
assert_equal "Summary of the news", presented_item.description | ||
end | ||
|
||
test "presents a body" do | ||
assert_equal "Some text", presented_item.body | ||
end | ||
|
||
test "presents a readable first published date" do | ||
assert_equal "25 December 2016", presented_item.published | ||
end | ||
|
||
test "presents the locale" do | ||
assert_equal "en", presented_item.locale | ||
end | ||
|
||
test "presents historically political" do | ||
assert presented_item.historically_political? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters