Skip to content

Commit 737e4b0

Browse files
author
Lee Richmond
committed
Ensure multiple filters work with legacy syntax
We should be using the graphiti dot syntax (e.g. `positions.active`) instead of the legacy (e.g. `positions[active]`). But let's make sure to support the legacy syntax for old users upgrading.
1 parent ca94cab commit 737e4b0

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lib/graphiti/query.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ def filters
126126
name = name.to_sym
127127

128128
if legacy_nested?(name)
129-
filter_name = value.keys.first.to_sym
130-
filter_value = value.values.first
131-
if @resource.get_attr!(filter_name, :filterable, request: true)
132-
hash[filter_name] = filter_value
129+
value.keys.each do |key|
130+
filter_name = key.to_sym
131+
filter_value = value[key]
132+
133+
if @resource.get_attr!(filter_name, :filterable, request: true)
134+
hash[filter_name] = filter_value
135+
end
133136
end
134137
elsif nested?(name)
135138
name = name.to_s.split(".").last.to_sym

lib/graphiti/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Graphiti
2-
VERSION = "1.2.14"
2+
VERSION = "1.2.15"
33
end

spec/query_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@
265265
expect(hash).to eq(expected)
266266
end
267267

268+
context 'with multiple filters' do
269+
before do
270+
params[:filter][:positions][:id] = 4
271+
end
272+
273+
it 'keeps both filters' do
274+
expect(hash[:include][:positions][:filter])
275+
.to eq(title: 'bar', id: 4)
276+
end
277+
end
278+
268279
context "with stringified keys" do
269280
before do
270281
params.deep_stringify_keys!

0 commit comments

Comments
 (0)