Skip to content

Commit

Permalink
Merge pull request #528 from supabase/or/list-filters-support-is
Browse files Browse the repository at this point in the history
Add support for IS filtering for ListFilter types
  • Loading branch information
olirice authored Jun 7, 2024
2 parents 8569ebb + 7030e05 commit adeb4c4
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ Where the `<Table>Filter` type enumerates filterable fields and their associated
containedBy: [String!]
eq: [String!]
overlaps: [String!]
is: FilterIs
}
```

Expand Down
10 changes: 10 additions & 0 deletions docs/assets/demo_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ input BigFloatListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

"""An arbitrary size integer represented as a string"""
Expand Down Expand Up @@ -160,6 +161,7 @@ input BigIntListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

type Blog implements Node {
Expand Down Expand Up @@ -414,6 +416,7 @@ input BooleanListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

"""
Expand Down Expand Up @@ -446,6 +449,7 @@ input DateListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

"""A date and time"""
Expand Down Expand Up @@ -473,6 +477,7 @@ input DatetimeListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

enum FilterIs {
Expand Down Expand Up @@ -502,6 +507,7 @@ input FloatListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

"""
Expand Down Expand Up @@ -533,6 +539,7 @@ input IntListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

"""A Javascript Object Notation value serialized as a string"""
Expand Down Expand Up @@ -783,6 +790,7 @@ input StringListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

"""A time without date information"""
Expand Down Expand Up @@ -810,6 +818,7 @@ input TimeListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}

"""A universally unique identifier"""
Expand All @@ -833,4 +842,5 @@ input UUIDListFilter {
contains: [BigFloat!]
eq: [BigFloat!]
overlaps: [BigFloat!]
is: FilterIs
}
11 changes: 11 additions & 0 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3608,11 +3608,22 @@ impl ___Type for FilterTypeType {
FilterOp::ContainedBy,
FilterOp::Equal,
FilterOp::Overlap,
FilterOp::Is,
];

supported_ops
.iter()
.map(|op| match op {
FilterOp::Is => __InputValue {
name_: "is".to_string(),
type_: __Type::Enum(EnumType {
enum_: EnumSource::FilterIs,
schema: Arc::clone(&self.schema),
}),
description: None,
default_value: None,
sql_type: None,
},
_ => __InputValue {
name_: op.to_string(),
type_: __Type::List(ListType {
Expand Down
86 changes: 64 additions & 22 deletions test/expected/resolve_connection_filter.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ begin;
values
(1, true, 'foo', '1111111111', '{"customer", "priority"}'),
(2, true, 'bar', null, '{"customer"}'),
(3, false, 'baz', '33333333333', '{"lead", "priority"}');
(3, false, 'baz', '33333333333', '{"lead", "priority"}'),
(4, false, 'qui', '4585858', null);
savepoint a;
-- Filter by Int
select jsonb_pretty(
Expand Down Expand Up @@ -137,6 +138,11 @@ begin;
"node": { +
"id": 3+
} +
}, +
{ +
"node": { +
"id": 4+
} +
} +
] +
} +
Expand All @@ -146,17 +152,17 @@ begin;

-- filter = null is ignored
select graphql.resolve($${accountCollection(filter: null) { edges { node { id } } }}$$);
resolve
-------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
resolve
----------------------------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
(1 row)

rollback to savepoint a;
-- neq
select graphql.resolve($${accountCollection(filter: {id: {neq: 2}}) { edges { node { id } } }}$$);
resolve
----------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}]}}}
resolve
-------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
(1 row)

rollback to savepoint a;
Expand Down Expand Up @@ -186,17 +192,17 @@ begin;
rollback to savepoint a;
-- gte
select graphql.resolve($${accountCollection(filter: {id: {gte: 2}}) { edges { node { id } } }}$$);
resolve
----------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 2}}, {"node": {"id": 3}}]}}}
resolve
-------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
(1 row)

rollback to savepoint a;
-- gt
select graphql.resolve($${accountCollection(filter: {id: {gt: 2}}) { edges { node { id } } }}$$);
resolve
-------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 3}}]}}}
resolve
----------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 3}}, {"node": {"id": 4}}]}}}
(1 row)

rollback to savepoint a;
Expand All @@ -210,9 +216,9 @@ begin;
rollback to savepoint a;
-- is - is not null
select graphql.resolve($${accountCollection(filter: {phone: {is: NOT_NULL}}) { edges { node { id } } }}$$);
resolve
----------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}]}}}
resolve
-------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
(1 row)

rollback to savepoint a;
Expand Down Expand Up @@ -412,6 +418,37 @@ begin;
(1 row)

rollback to savepoint a;
-- is - array column is NULL/NOT_NULL
select jsonb_pretty(
graphql.resolve($$
{
accountCollection(filter: {tags: {is: NULL}}) {
edges {
node {
id
}
}
}
}
$$)
);
jsonb_pretty
---------------------------------
{ +
"data": { +
"accountCollection": { +
"edges": [ +
{ +
"node": { +
"id": 4+
} +
} +
] +
} +
} +
}
(1 row)

-- variable is - is null
select graphql.resolve($$query AAA($nis: FilterIs) { accountCollection(filter: {phone: {is: $nis}}) { edges { node { id } } }}$$, '{"nis": "NULL"}');
resolve
Expand All @@ -422,9 +459,9 @@ begin;
rollback to savepoint a;
-- variable is - absent treated as ignored / returns all
select graphql.resolve($$query AAA($nis: FilterIs) { accountCollection(filter: {phone: {is: $nis}}) { edges { node { id } } }}$$, '{}');
resolve
-------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
resolve
----------------------------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
(1 row)

rollback to savepoint a;
Expand Down Expand Up @@ -478,9 +515,9 @@ begin;
rollback to savepoint a;
-- variable in - absent treated as ignored / returns all
select graphql.resolve($$query AAA($nin: [String!]) { accountCollection(filter: {name: {in: $nin}}) { edges { node { id } } }}$$, '{}');
resolve
-------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}]}}}
resolve
----------------------------------------------------------------------------------------------------------------------------------
{"data": {"accountCollection": {"edges": [{"node": {"id": 1}}, {"node": {"id": 2}}, {"node": {"id": 3}}, {"node": {"id": 4}}]}}}
(1 row)

rollback to savepoint a;
Expand Down Expand Up @@ -960,6 +997,11 @@ begin;
"node": { +
"id": 3+
} +
}, +
{ +
"node": { +
"id": 4+
} +
} +
] +
} +
Expand Down
Loading

0 comments on commit adeb4c4

Please sign in to comment.