Skip to content

Commit 9d752b8

Browse files
committed
fix(products): tolerate explicit null values on filter update
## Context The values argument of UpdateProductFilter is nullable, and graphql-ruby passes an explicitly-null argument through to the resolver as nil with the key present. ## Description Mapping nil to input hashes raised a NoMethodError, turning a malformed payload into an internal error. A null values list now reaches the validation layer and fails with value_is_mandatory like an empty one.
1 parent 5972621 commit 9d752b8

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

app/graphql/mutations/product_filters/update.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def resolve(**args)
1818
product_filter = current_organization.product_filters.find_by(id: args[:id])
1919

2020
params = args.except(:id)
21-
params[:values] = params[:values].map(&:to_h) if params.key?(:values)
21+
params[:values] = params[:values]&.map(&:to_h) if params.key?(:values)
2222

2323
result = ::ProductFilters::UpdateService.call(product_filter:, params:)
2424

spec/graphql/mutations/product_filters/update_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
expect(result_data["values"].map { [it["key"], it["value"]] }).to eq([%w[region eu]])
5757
end
5858

59+
context "when values is null" do
60+
let(:input) { {id: product_filter.id, name: "After", values: nil} }
61+
62+
it "returns a validation error" do
63+
expect_graphql_error(result: execution, message: :unprocessable_entity)
64+
end
65+
end
66+
5967
context "when the filter belongs to another organization" do
6068
let(:input) { {id: create(:product_filter).id, name: "After"} }
6169

0 commit comments

Comments
 (0)