Skip to content

Commit

Permalink
Merge pull request #3911 from alphagov/change-graphql-case
Browse files Browse the repository at this point in the history
Use snake cased field names for GraphQL
  • Loading branch information
brucebolt authored Dec 18, 2024
2 parents a03356a + 225535a commit e067951
Show file tree
Hide file tree
Showing 12 changed files with 342 additions and 345 deletions.
1 change: 0 additions & 1 deletion app/models/graphql/ministers_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def self.find!(base_path)

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

new(edition)
end
Expand Down
1 change: 0 additions & 1 deletion app/models/graphql/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def self.find!(base_path)

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

new(edition)
end
Expand Down
1 change: 0 additions & 1 deletion app/models/graphql/world_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def self.find!(base_path)

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

new(edition)
end
Expand Down
50 changes: 25 additions & 25 deletions app/queries/graphql/ministers_index_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,59 @@ def initialize(base_path)
def query
<<-QUERY
{
edition(basePath: "#{@base_path}") {
edition(base_path: "#{@base_path}") {
... on MinistersIndex {
basePath
base_path
links {
orderedCabinetMinisters {
ordered_cabinet_ministers {
...basePersonInfo
}
orderedAlsoAttendsCabinet {
ordered_also_attends_cabinet {
...basePersonInfo
}
orderedAssistantWhips {
ordered_assistant_whips {
...basePersonInfo
}
orderedBaronessesAndLordsInWaitingWhips {
ordered_baronesses_and_lords_in_waiting_whips {
...basePersonInfo
}
orderedHouseLordsWhips {
ordered_house_lords_whips {
...basePersonInfo
}
orderedHouseOfCommonsWhips {
ordered_house_of_commons_whips {
...basePersonInfo
}
orderedJuniorLordsOfTheTreasuryWhips {
ordered_junior_lords_of_the_treasury_whips {
...basePersonInfo
}
orderedMinisterialDepartments {
ordered_ministerial_departments {
title
webUrl
web_url
details {
brand
logo {
crest
formattedTitle
formatted_title
}
}
links {
orderedMinisters {
ordered_ministers {
...basePersonInfo
}
orderedRoles {
contentId
ordered_roles {
content_id
}
}
}
Expand All @@ -69,36 +69,36 @@ def query
fragment basePersonInfo on MinistersIndexPerson {
title
basePath
webUrl
base_path
web_url
details {
privyCounsellor
privy_counsellor
image {
url
altText
alt_text
}
}
links {
roleAppointments {
role_appointments {
details {
current
}
links {
role {
contentId
content_id
title
webUrl
web_url
details {
rolePaymentType
role_payment_type
seniority
whipOrganisation {
whip_organisation {
label
sortOrder
sort_order
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions app/queries/graphql/role_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ def initialize(base_path)
def query
<<-QUERY
{
edition(basePath: "#{@base_path}") {
edition(base_path: "#{@base_path}") {
... on Role {
basePath
base_path
locale
title
details {
body
supportsHistoricalAccounts
supports_historical_accounts
}
links {
availableTranslations {
basePath
available_translations {
base_path
locale
}
roleAppointments {
role_appointments {
details {
current
endedOn
startedOn
ended_on
started_on
}
links {
person {
basePath
base_path
title
details {
Expand All @@ -42,8 +42,8 @@ def query
}
}
orderedParentOrganisations {
basePath
ordered_parent_organisations {
base_path
title
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/queries/graphql/world_index_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ def query
}
{
edition(basePath: "#{@base_path}") {
edition(base_path: "#{@base_path}") {
... on WorldIndex {
title
details {
worldLocations {
world_locations {
...worldLocationInfo
}
internationalDelegations {
international_delegations {
...worldLocationInfo
}
}
Expand Down
12 changes: 6 additions & 6 deletions spec/features/role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
let(:role_edition_data) do
fetch_graphql_fixture("prime_minister")
.tap do |fixture|
any_current = fixture["data"]["edition"]["links"]["roleAppointments"]
any_current = fixture["data"]["edition"]["links"]["role_appointments"]
.any? { |ra| ra["details"]["current"] == true }

unless any_current
links = fixture["data"]["edition"]["links"]
links["roleAppointments"][0]["details"]["current"] = true
links["role_appointments"][0]["details"]["current"] = true
end
end
end
Expand All @@ -46,12 +46,12 @@
let(:role_edition_data) do
fetch_graphql_fixture("prime_minister")
.tap do |fixture|
current = fixture["data"]["edition"]["links"]["roleAppointments"]
current = fixture["data"]["edition"]["links"]["role_appointments"]
.find { |ra| ra["details"]["current"] == true }

if current
current["details"]["current"] = false
current["details"]["endedOn"] = Time.zone.now
current["details"]["ended_on"] = Time.zone.now
end
end
end
Expand All @@ -65,7 +65,7 @@
let(:role_edition_data) do
fetch_graphql_fixture("prime_minister")
.tap do |fixture|
fixture["data"]["edition"]["details"]["supportsHistoricalAccounts"] = true
fixture["data"]["edition"]["details"]["supports_historical_accounts"] = true
end
end

Expand All @@ -78,7 +78,7 @@
let(:role_edition_data) do
fetch_graphql_fixture("prime_minister")
.tap do |fixture|
fixture["data"]["edition"]["details"]["supportsHistoricalAccounts"] = false
fixture["data"]["edition"]["details"]["supports_historical_accounts"] = false
end
end

Expand Down
Loading

0 comments on commit e067951

Please sign in to comment.