Skip to content

Commit

Permalink
Merge pull request #3908 from alphagov/update-world-index-shape
Browse files Browse the repository at this point in the history
Update GraphQL approach for world index
  • Loading branch information
yndajas authored Dec 16, 2024
2 parents f66b6bc + dd98c9f commit fb54b33
Show file tree
Hide file tree
Showing 8 changed files with 1,239 additions and 1,327 deletions.
11 changes: 6 additions & 5 deletions app/controllers/world_controller.rb
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)
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
17 changes: 17 additions & 0 deletions app/models/graphql/world_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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

edition = Services.publishing_api.graphql_query(query)
.dig("data", "edition")
.deep_transform_keys(&:underscore)

new(edition)
end
end
15 changes: 0 additions & 15 deletions app/presenters/world_index_graphql_presenter.rb

This file was deleted.

14 changes: 7 additions & 7 deletions app/presenters/world_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ class WorldIndexPresenter
delegate :count, to: :world_locations, prefix: true
delegate :count, to: :international_delegations, prefix: true

def initialize(world_index)
@world_index = world_index
def initialize(content_item_data)
@content_item_data = content_item_data
end

def title
@world_index.content_item.title
@content_item_data.fetch("title")
end

def grouped_world_locations
world_locations
@content_item_data.dig("details", "world_locations")
.group_by { |location| location_group(location) }
.sort
end

def international_delegations
details["international_delegations"]
@content_item_data.dig("details", "international_delegations")
end

def world_location_link(world_location)
Expand All @@ -45,10 +45,10 @@ def location_group(location)
end

def details
@world_index.content_item.details
@content_item_data.fetch("details")
end

def world_locations
details["world_locations"]
@content_item_data.dig("details", "world_locations")
end
end
12 changes: 7 additions & 5 deletions app/queries/graphql/world_index_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ def query
... on WorldIndex {
title
worldLocations {
...worldLocationInfo
}
details {
worldLocations {
...worldLocationInfo
}
internationalDelegations {
...worldLocationInfo
internationalDelegations {
...worldLocationInfo
}
}
}
}
Expand Down
Loading

0 comments on commit fb54b33

Please sign in to comment.