Skip to content

Commit adeb4c4

Browse files
authored
Merge pull request #528 from supabase/or/list-filters-support-is
Add support for IS filtering for ListFilter types
2 parents 8569ebb + 7030e05 commit adeb4c4

File tree

6 files changed

+203
-23
lines changed

6 files changed

+203
-23
lines changed

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ Where the `<Table>Filter` type enumerates filterable fields and their associated
587587
containedBy: [String!]
588588
eq: [String!]
589589
overlaps: [String!]
590+
is: FilterIs
590591
}
591592
```
592593

docs/assets/demo_schema.graphql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ input BigFloatListFilter {
133133
contains: [BigFloat!]
134134
eq: [BigFloat!]
135135
overlaps: [BigFloat!]
136+
is: FilterIs
136137
}
137138

138139
"""An arbitrary size integer represented as a string"""
@@ -160,6 +161,7 @@ input BigIntListFilter {
160161
contains: [BigFloat!]
161162
eq: [BigFloat!]
162163
overlaps: [BigFloat!]
164+
is: FilterIs
163165
}
164166

165167
type Blog implements Node {
@@ -414,6 +416,7 @@ input BooleanListFilter {
414416
contains: [BigFloat!]
415417
eq: [BigFloat!]
416418
overlaps: [BigFloat!]
419+
is: FilterIs
417420
}
418421

419422
"""
@@ -446,6 +449,7 @@ input DateListFilter {
446449
contains: [BigFloat!]
447450
eq: [BigFloat!]
448451
overlaps: [BigFloat!]
452+
is: FilterIs
449453
}
450454

451455
"""A date and time"""
@@ -473,6 +477,7 @@ input DatetimeListFilter {
473477
contains: [BigFloat!]
474478
eq: [BigFloat!]
475479
overlaps: [BigFloat!]
480+
is: FilterIs
476481
}
477482

478483
enum FilterIs {
@@ -502,6 +507,7 @@ input FloatListFilter {
502507
contains: [BigFloat!]
503508
eq: [BigFloat!]
504509
overlaps: [BigFloat!]
510+
is: FilterIs
505511
}
506512

507513
"""
@@ -533,6 +539,7 @@ input IntListFilter {
533539
contains: [BigFloat!]
534540
eq: [BigFloat!]
535541
overlaps: [BigFloat!]
542+
is: FilterIs
536543
}
537544

538545
"""A Javascript Object Notation value serialized as a string"""
@@ -783,6 +790,7 @@ input StringListFilter {
783790
contains: [BigFloat!]
784791
eq: [BigFloat!]
785792
overlaps: [BigFloat!]
793+
is: FilterIs
786794
}
787795

788796
"""A time without date information"""
@@ -810,6 +818,7 @@ input TimeListFilter {
810818
contains: [BigFloat!]
811819
eq: [BigFloat!]
812820
overlaps: [BigFloat!]
821+
is: FilterIs
813822
}
814823

815824
"""A universally unique identifier"""
@@ -833,4 +842,5 @@ input UUIDListFilter {
833842
contains: [BigFloat!]
834843
eq: [BigFloat!]
835844
overlaps: [BigFloat!]
845+
is: FilterIs
836846
}

src/graphql.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,11 +3608,22 @@ impl ___Type for FilterTypeType {
36083608
FilterOp::ContainedBy,
36093609
FilterOp::Equal,
36103610
FilterOp::Overlap,
3611+
FilterOp::Is,
36113612
];
36123613

36133614
supported_ops
36143615
.iter()
36153616
.map(|op| match op {
3617+
FilterOp::Is => __InputValue {
3618+
name_: "is".to_string(),
3619+
type_: __Type::Enum(EnumType {
3620+
enum_: EnumSource::FilterIs,
3621+
schema: Arc::clone(&self.schema),
3622+
}),
3623+
description: None,
3624+
default_value: None,
3625+
sql_type: None,
3626+
},
36163627
_ => __InputValue {
36173628
name_: op.to_string(),
36183629
type_: __Type::List(ListType {

test/expected/resolve_connection_filter.out

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ begin;
1010
values
1111
(1, true, 'foo', '1111111111', '{"customer", "priority"}'),
1212
(2, true, 'bar', null, '{"customer"}'),
13-
(3, false, 'baz', '33333333333', '{"lead", "priority"}');
13+
(3, false, 'baz', '33333333333', '{"lead", "priority"}'),
14+
(4, false, 'qui', '4585858', null);
1415
savepoint a;
1516
-- Filter by Int
1617
select jsonb_pretty(
@@ -137,6 +138,11 @@ begin;
137138
"node": { +
138139
"id": 3+
139140
} +
141+
}, +
142+
{ +
143+
"node": { +
144+
"id": 4+
145+
} +
140146
} +
141147
] +
142148
} +
@@ -146,17 +152,17 @@ begin;
146152

147153
-- filter = null is ignored
148154
select graphql.resolve($${accountCollection(filter: null) { edges { node { id } } }}$$);
149-
resolve
150-
-------------------------------------------------------------------------------------------------------------
151-
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
155+
resolve
156+
----------------------------------------------------------------------------------------------------------------------------------
157+
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
152158
(1 row)
153159

154160
rollback to savepoint a;
155161
-- neq
156162
select graphql.resolve($${accountCollection(filter: {id: {neq: 2}}) { edges { node { id } } }}$$);
157-
resolve
158-
----------------------------------------------------------------------------------------
159-
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}]}}}
163+
resolve
164+
-------------------------------------------------------------------------------------------------------------
165+
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
160166
(1 row)
161167

162168
rollback to savepoint a;
@@ -186,17 +192,17 @@ begin;
186192
rollback to savepoint a;
187193
-- gte
188194
select graphql.resolve($${accountCollection(filter: {id: {gte: 2}}) { edges { node { id } } }}$$);
189-
resolve
190-
----------------------------------------------------------------------------------------
191-
{"data": {"accountCollection": {"edges": [{"node": {"id": 2}}, {"node": {"id": 3}}]}}}
195+
resolve
196+
-------------------------------------------------------------------------------------------------------------
197+
{"data": {"accountCollection": {"edges": [{"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
192198
(1 row)
193199

194200
rollback to savepoint a;
195201
-- gt
196202
select graphql.resolve($${accountCollection(filter: {id: {gt: 2}}) { edges { node { id } } }}$$);
197-
resolve
198-
-------------------------------------------------------------------
199-
{"data": {"accountCollection": {"edges": [{"node": {"id": 3}}]}}}
203+
resolve
204+
----------------------------------------------------------------------------------------
205+
{"data": {"accountCollection": {"edges": [{"node": {"id": 3}}, {"node": {"id": 4}}]}}}
200206
(1 row)
201207

202208
rollback to savepoint a;
@@ -210,9 +216,9 @@ begin;
210216
rollback to savepoint a;
211217
-- is - is not null
212218
select graphql.resolve($${accountCollection(filter: {phone: {is: NOT_NULL}}) { edges { node { id } } }}$$);
213-
resolve
214-
----------------------------------------------------------------------------------------
215-
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}]}}}
219+
resolve
220+
-------------------------------------------------------------------------------------------------------------
221+
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
216222
(1 row)
217223

218224
rollback to savepoint a;
@@ -412,6 +418,37 @@ begin;
412418
(1 row)
413419

414420
rollback to savepoint a;
421+
-- is - array column is NULL/NOT_NULL
422+
select jsonb_pretty(
423+
graphql.resolve($$
424+
{
425+
accountCollection(filter: {tags: {is: NULL}}) {
426+
edges {
427+
node {
428+
id
429+
}
430+
}
431+
}
432+
}
433+
$$)
434+
);
435+
jsonb_pretty
436+
---------------------------------
437+
{ +
438+
"data": { +
439+
"accountCollection": { +
440+
"edges": [ +
441+
{ +
442+
"node": { +
443+
"id": 4+
444+
} +
445+
} +
446+
] +
447+
} +
448+
} +
449+
}
450+
(1 row)
451+
415452
-- variable is - is null
416453
select graphql.resolve($$query AAA($nis: FilterIs) { accountCollection(filter: {phone: {is: $nis}}) { edges { node { id } } }}$$, '{"nis": "NULL"}');
417454
resolve
@@ -422,9 +459,9 @@ begin;
422459
rollback to savepoint a;
423460
-- variable is - absent treated as ignored / returns all
424461
select graphql.resolve($$query AAA($nis: FilterIs) { accountCollection(filter: {phone: {is: $nis}}) { edges { node { id } } }}$$, '{}');
425-
resolve
426-
-------------------------------------------------------------------------------------------------------------
427-
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
462+
resolve
463+
----------------------------------------------------------------------------------------------------------------------------------
464+
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
428465
(1 row)
429466

430467
rollback to savepoint a;
@@ -478,9 +515,9 @@ begin;
478515
rollback to savepoint a;
479516
-- variable in - absent treated as ignored / returns all
480517
select graphql.resolve($$query AAA($nin: [String!]) { accountCollection(filter: {name: {in: $nin}}) { edges { node { id } } }}$$, '{}');
481-
resolve
482-
-------------------------------------------------------------------------------------------------------------
483-
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
518+
resolve
519+
----------------------------------------------------------------------------------------------------------------------------------
520+
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
484521
(1 row)
485522

486523
rollback to savepoint a;
@@ -960,6 +997,11 @@ begin;
960997
"node": { +
961998
"id": 3+
962999
} +
1000+
}, +
1001+
{ +
1002+
"node": { +
1003+
"id": 4+
1004+
} +
9631005
} +
9641006
] +
9651007
} +

0 commit comments

Comments
 (0)