Skip to content

Commit 5979c49

Browse files
committed
refactor(products): keep relation names on GraphQL errors
## Context GraphQL product mutations remapped model association errors to the id input fields (billable_metric_id, product_category_id) through a SurfaceErrorFields concern. The FE owns its error-display mapping, so the neutral relation name is enough on GraphQL — while REST keeps translating to the _code params its callers actually send, where the contract is public. ## Description Drop the SurfaceErrorFields concern: GraphQL validation errors now carry the relation name emitted by the model. The REST boundary keeps its billable_metric_code and product_category_code mapping.
1 parent 86242c9 commit 5979c49

4 files changed

Lines changed: 4 additions & 31 deletions

File tree

app/graphql/mutations/products/create.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Products
55
class Create < BaseMutation
66
include AuthenticableApiUser
77
include RequiredOrganization
8-
include SurfaceErrorFields
98

109
REQUIRED_PERMISSION = "products:create"
1110

@@ -18,7 +17,7 @@ class Create < BaseMutation
1817
def resolve(**args)
1918
result = ::Products::CreateService.call(organization: current_organization, params: args)
2019

21-
result.success? ? result.product : render_item_error(result)
20+
result.success? ? result.product : result_error(result)
2221
end
2322
end
2423
end

app/graphql/mutations/products/surface_error_fields.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/graphql/mutations/products/update.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Products
55
class Update < BaseMutation
66
include AuthenticableApiUser
77
include RequiredOrganization
8-
include SurfaceErrorFields
98

109
REQUIRED_PERMISSION = "products:update"
1110

@@ -19,7 +18,7 @@ def resolve(**args)
1918
product = current_organization.products.find_by(id: args[:id])
2019
result = ::Products::UpdateService.call(product:, params: args.except(:id))
2120

22-
result.success? ? result.product : render_item_error(result)
21+
result.success? ? result.product : result_error(result)
2322
end
2423
end
2524
end

spec/graphql/mutations/products/create_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
context "when a usage item has no billable metric" do
7272
let(:input) { {name: "Orphan", code: "orphan", productType: "usage"} }
7373

74-
it "returns a validation error on billable_metric_id" do
75-
expect(execution["errors"].first["extensions"]["details"]).to eq("billableMetricId" => ["value_is_mandatory"])
74+
it "returns a validation error on the relation" do
75+
expect(execution["errors"].first["extensions"]["details"]).to eq("billableMetric" => ["value_is_mandatory"])
7676
end
7777
end
7878
end

0 commit comments

Comments
 (0)