Skip to content

Commit

Permalink
Merge pull request #3049 from alphagov/graphql-field-case
Browse files Browse the repository at this point in the history
Switch off auto-camelization for GraphQL fields
  • Loading branch information
brucebolt authored Dec 18, 2024
2 parents b445ba5 + 07dff3e commit a6b081e
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 269 deletions.
3 changes: 3 additions & 0 deletions app/graphql/types/base_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

module Types
class BaseArgument < GraphQL::Schema::Argument
def initialize(*args, camelize: false, **kwargs, &block)
super
end
end
end
4 changes: 4 additions & 0 deletions app/graphql/types/base_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
module Types
class BaseField < GraphQL::Schema::Field
argument_class Types::BaseArgument

def initialize(*args, camelize: false, **kwargs, &block)
super
end
end
end
4 changes: 2 additions & 2 deletions spec/graphql/types/edition_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

expect(
run_graphql_field(
"Edition.withdrawnNotice",
"Edition.withdrawn_notice",
edition,
),
).to eq(expected)
Expand All @@ -23,7 +23,7 @@
it "returns nil" do
expect(
run_graphql_field(
"Edition.withdrawnNotice",
"Edition.withdrawn_notice",
create(:edition),
),
).to be_nil
Expand Down
26 changes: 13 additions & 13 deletions spec/graphql/types/query_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
describe "#edition" do
let(:query) do
<<~QUERY
query($basePath: String!, $contentStore: String!) {
edition(basePath: $basePath, contentStore: $contentStore) {
query($base_path: String!, $content_store: String!) {
edition(base_path: $base_path, content_store: $content_store) {
... on Edition {
basePath
base_path
state
}
}
Expand All @@ -21,19 +21,19 @@
context "requesting the draft edition" do
it "returns the draft edition" do
expected_data = {
"basePath" => draft_edition.base_path,
"base_path" => draft_edition.base_path,
"state" => "draft",
}

result = PublishingApiSchema.execute(query, variables: { basePath: draft_edition.base_path, contentStore: "draft" })
result = PublishingApiSchema.execute(query, variables: { base_path: draft_edition.base_path, content_store: "draft" })
edition_data = result.dig("data", "edition")
expect(edition_data).to eq(expected_data)
end
end

context "requesting the live edition" do
it "returns no edition" do
result = PublishingApiSchema.execute(query, variables: { basePath: draft_edition.base_path, contentStore: "live" })
result = PublishingApiSchema.execute(query, variables: { base_path: draft_edition.base_path, content_store: "live" })
edition_data = result.dig("data", "edition")
expect(edition_data).to be_nil
end
Expand All @@ -45,7 +45,7 @@

context "requesting the draft edition" do
it "returns no edition" do
result = PublishingApiSchema.execute(query, variables: { basePath: live_edition.base_path, contentStore: "draft" })
result = PublishingApiSchema.execute(query, variables: { base_path: live_edition.base_path, content_store: "draft" })
edition_data = result.dig("data", "edition")
expect(edition_data).to be_nil
end
Expand All @@ -54,11 +54,11 @@
context "requesting the live edition" do
it "returns the live edition" do
expected_data = {
"basePath" => live_edition.base_path,
"base_path" => live_edition.base_path,
"state" => "published",
}

result = PublishingApiSchema.execute(query, variables: { basePath: live_edition.base_path, contentStore: "live" })
result = PublishingApiSchema.execute(query, variables: { base_path: live_edition.base_path, content_store: "live" })
edition_data = result.dig("data", "edition")
expect(edition_data).to eq(expected_data)
end
Expand All @@ -74,11 +74,11 @@
context "requesting the draft edition" do
it "returns the draft edition" do
expected_data = {
"basePath" => draft_edition.base_path,
"base_path" => draft_edition.base_path,
"state" => "draft",
}

result = PublishingApiSchema.execute(query, variables: { basePath: draft_edition.base_path, contentStore: "draft" })
result = PublishingApiSchema.execute(query, variables: { base_path: draft_edition.base_path, content_store: "draft" })
edition_data = result.dig("data", "edition")
expect(edition_data).to eq(expected_data)
end
Expand All @@ -87,11 +87,11 @@
context "requesting the live edition" do
it "returns the live edition" do
expected_data = {
"basePath" => live_edition.base_path,
"base_path" => live_edition.base_path,
"state" => "published",
}

result = PublishingApiSchema.execute(query, variables: { basePath: live_edition.base_path, contentStore: "live" })
result = PublishingApiSchema.execute(query, variables: { base_path: live_edition.base_path, content_store: "live" })
edition_data = result.dig("data", "edition")
expect(edition_data).to eq(expected_data)
end
Expand Down
76 changes: 38 additions & 38 deletions spec/integration/graphql/generic_edition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
post "/graphql", params: {
query:
"{
edition(basePath: \"/my/generic/edition\") {
edition(base_path: \"/my/generic/edition\") {
... on Edition {
title
analyticsIdentifier
basePath
contentId
analytics_identifier
base_path
content_id
description
details
documentType
firstPublishedAt
document_type
first_published_at
locale
phase
publicUpdatedAt
publishingApp
publishingRequestId
publishingScheduledAt
renderingApp
scheduledPublishingDelaySeconds
schemaName
updatedAt
withdrawnNotice {
public_updated_at
publishing_app
publishing_request_id
publishing_scheduled_at
rendering_app
scheduled_publishing_delay_seconds
schema_name
updated_at
withdrawn_notice {
explanation
withdrawnAt
withdrawn_at
}
}
}
Expand All @@ -41,25 +41,25 @@
expected = {
"data": {
"edition": {
"analyticsIdentifier": @edition.analytics_identifier,
"basePath": @edition.base_path,
"contentId": @edition.content_id,
"analytics_identifier": @edition.analytics_identifier,
"base_path": @edition.base_path,
"content_id": @edition.content_id,
"description": @edition.description,
"details": @edition.details,
"documentType": @edition.document_type,
"firstPublishedAt": @edition.first_published_at.iso8601,
"document_type": @edition.document_type,
"first_published_at": @edition.first_published_at.iso8601,
"locale": @edition.locale,
"phase": @edition.phase,
"publicUpdatedAt": @edition.public_updated_at.iso8601,
"publishingApp": @edition.publishing_app,
"publishingRequestId": @edition.publishing_request_id,
"publishingScheduledAt": nil,
"renderingApp": @edition.rendering_app,
"scheduledPublishingDelaySeconds": nil,
"schemaName": @edition.schema_name,
"public_updated_at": @edition.public_updated_at.iso8601,
"publishing_app": @edition.publishing_app,
"publishing_request_id": @edition.publishing_request_id,
"publishing_scheduled_at": nil,
"rendering_app": @edition.rendering_app,
"scheduled_publishing_delay_seconds": nil,
"schema_name": @edition.schema_name,
"title": @edition.title,
"updatedAt": @edition.updated_at.iso8601,
"withdrawnNotice": nil,
"updated_at": @edition.updated_at.iso8601,
"withdrawn_notice": nil,
},
},
}
Expand All @@ -84,11 +84,11 @@
post "/graphql", params: {
query:
"{
edition(basePath: \"/my/withdrawn/edition\") {
edition(base_path: \"/my/withdrawn/edition\") {
... on Edition {
withdrawnNotice {
withdrawn_notice {
explanation
withdrawnAt
withdrawn_at
}
}
}
Expand All @@ -98,9 +98,9 @@
expected = {
"data": {
"edition": {
"withdrawnNotice": {
"withdrawn_notice": {
"explanation": "for integration testing",
"withdrawnAt": "2024-10-27T17:00:00Z",
"withdrawn_at": "2024-10-27T17:00:00Z",
},
},
},
Expand All @@ -116,9 +116,9 @@
post "/graphql", params: {
query:
"{
edition(basePath: \"/my/generic/edition\") {
edition(base_path: \"/my/generic/edition\") {
... on Edition {
worldLocations {
world_locations {
active
}
}
Expand All @@ -132,7 +132,7 @@
{
errors: [
hash_including(
message: "Field 'worldLocations' doesn't exist on type 'Edition'",
message: "Field 'world_locations' doesn't exist on type 'Edition'",
),
],
},
Expand Down
Loading

0 comments on commit a6b081e

Please sign in to comment.