-
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.
Update GraphQL approach for world index
Given we're still in the learning stage with the GraphQL project, we've decided to minimise the changes needed on frontend apps by retaining the current heavily nested data structure. This updates Collections to work with that format (the changes to Publishing API are also in progress). This means that the code for the world index page in collections will be less divergent between paths for GraphQL and REST data sources. This commit undoes some of the divergence we initially introduced We plan to revisit simplifying the data structure later (into a less nested form)
- Loading branch information
Showing
7 changed files
with
41 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
class WorldController < ApplicationController | ||
def index | ||
if Features.graphql_feature_enabled? || params.include?(:graphql) | ||
index = WorldIndexGraphql.find!("/world") | ||
@presented_index = WorldIndexGraphqlPresenter.new(index) | ||
if params.include?(:graphql) | ||
world_index = Graphql::WorldIndex.find!(request.path) | ||
content_item_data = world_index.content_item | ||
else | ||
index = WorldIndex.find!("/world") | ||
@presented_index = WorldIndexPresenter.new(index) | ||
world_index = WorldIndex.find!(request.path) | ||
content_item_data = world_index.content_item.content_item_data | ||
end | ||
|
||
setup_content_item_and_navigation_helpers(index) | ||
@presented_index = WorldIndexPresenter.new(content_item_data) | ||
setup_content_item_and_navigation_helpers(world_index) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Graphql::WorldIndex | ||
attr_reader :content_item | ||
|
||
def initialize(content_item) | ||
@content_item = content_item | ||
end | ||
|
||
def self.find!(base_path) | ||
query = Graphql::WorldIndexQuery.new(base_path).query | ||
|
||
# binding.pry | ||
|
||
edition = Services.publishing_api.graphql_query(query) | ||
.dig("data", "edition") | ||
.deep_transform_keys(&:underscore) | ||
|
||
new(edition) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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