Skip to content

Commit

Permalink
Update GraphQL world index details type
Browse files Browse the repository at this point in the history
For subsequent types, we've chosen to follow the existing pattern of
nesting most type-specific data in a details hash. This makes it easier
to get GraphQL working on frontends while we're still in the learning
stage. We plan to revisit simplifying the data structure later
  • Loading branch information
yndajas committed Dec 13, 2024
1 parent 5fb4f37 commit b1d9756
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
14 changes: 5 additions & 9 deletions app/graphql/types/world_index_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ class WorldLocation < Types::BaseObject
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
end

field :body, String
field :international_delegations, [WorldLocation], null: false
field :world_locations, [WorldLocation], null: false

def international_delegations
object.details[:international_delegations]
class WorldIndexDetails < BaseObject
field :body, String
field :international_delegations, [WorldLocation], null: false
field :world_locations, [WorldLocation], null: false
end

def world_locations
object.details[:world_locations]
end
field :details, WorldIndexDetails
end
end
54 changes: 29 additions & 25 deletions spec/integration/graphql/world_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@
... on WorldIndex {
title
worldLocations {
...worldLocationInfo
}
details {
worldLocations {
...worldLocationInfo
}
internationalDelegations {
...worldLocationInfo
internationalDelegations {
...worldLocationInfo
}
}
}
}
Expand All @@ -67,26 +69,28 @@
data: {
edition: {
title: "Help and services around the world",
worldLocations: [
{
active: true,
analyticsIdentifier: "WL1",
contentId: "d3b7ba48-5027-4a98-a594-1108d205dc66",
name: "Test World Location",
slug: "test-world-location",
updatedAt: "2024-10-18T14:22:38+01:00",
},
],
internationalDelegations: [
{
active: false,
analyticsIdentifier: "WL2",
contentId: "f0313f16-e25c-4bfe-a0fc-e561833f705f",
name: "Test International Delegation",
slug: "test-international-delegation",
updatedAt: "2024-10-19T15:07:44+01:00",
},
],
details: {
worldLocations: [
{
active: true,
analyticsIdentifier: "WL1",
contentId: "d3b7ba48-5027-4a98-a594-1108d205dc66",
name: "Test World Location",
slug: "test-world-location",
updatedAt: "2024-10-18T14:22:38+01:00",
},
],
internationalDelegations: [
{
active: false,
analyticsIdentifier: "WL2",
contentId: "f0313f16-e25c-4bfe-a0fc-e561833f705f",
name: "Test International Delegation",
slug: "test-international-delegation",
updatedAt: "2024-10-19T15:07:44+01:00",
},
],
},
},
},
}
Expand Down

0 comments on commit b1d9756

Please sign in to comment.