Skip to content

Commit 359d2f5

Browse files
committed
Add is operator as a potential replacement for null operator
1 parent 7ad3fba commit 359d2f5

File tree

4 files changed

+174
-1
lines changed

4 files changed

+174
-1
lines changed

__tests__/fixtures/queries/connections-filter.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
query {
2+
string_is_null: allFilterables(filter: { string: { is: NULL } }) { ...filterableConnection }
3+
string_is_not_null: allFilterables(filter: { string: { is: NOT_NULL } }) { ...filterableConnection }
24
string_null_true: allFilterables(filter: { string: { null: true } }) { ...filterableConnection }
35
string_null_false: allFilterables(filter: { string: { null: false } }) { ...filterableConnection }
46
string_equalTo_test: allFilterables(filter: { string: { equalTo: "test" } }) { ...filterableConnection }

__tests__/integration/__snapshots__/queries.test.js.snap

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,83 @@ Object {
15181518
},
15191519
"totalCount": 1,
15201520
},
1521+
"string_is_not_null": Object {
1522+
"edges": Array [
1523+
Object {
1524+
"cursor": "WyJwcmltYXJ5X2tleV9hc2MiLFsxXV0=",
1525+
"node": Object {
1526+
"boolean": true,
1527+
"id": 1,
1528+
"int": 1,
1529+
"numeric": "0.1",
1530+
"real": 0.1,
1531+
"string": "TEST",
1532+
},
1533+
},
1534+
Object {
1535+
"cursor": "WyJwcmltYXJ5X2tleV9hc2MiLFsyXV0=",
1536+
"node": Object {
1537+
"boolean": true,
1538+
"id": 2,
1539+
"int": 2,
1540+
"numeric": "0.2",
1541+
"real": 0.2,
1542+
"string": "Test",
1543+
},
1544+
},
1545+
Object {
1546+
"cursor": "WyJwcmltYXJ5X2tleV9hc2MiLFszXV0=",
1547+
"node": Object {
1548+
"boolean": false,
1549+
"id": 3,
1550+
"int": 3,
1551+
"numeric": "0.3",
1552+
"real": 0.3,
1553+
"string": "tEST",
1554+
},
1555+
},
1556+
Object {
1557+
"cursor": "WyJwcmltYXJ5X2tleV9hc2MiLFs0XV0=",
1558+
"node": Object {
1559+
"boolean": false,
1560+
"id": 4,
1561+
"int": 4,
1562+
"numeric": "0.4",
1563+
"real": 0.4,
1564+
"string": "test",
1565+
},
1566+
},
1567+
],
1568+
"pageInfo": Object {
1569+
"endCursor": "WyJwcmltYXJ5X2tleV9hc2MiLFs0XV0=",
1570+
"hasNextPage": false,
1571+
"hasPreviousPage": false,
1572+
"startCursor": "WyJwcmltYXJ5X2tleV9hc2MiLFsxXV0=",
1573+
},
1574+
"totalCount": 4,
1575+
},
1576+
"string_is_null": Object {
1577+
"edges": Array [
1578+
Object {
1579+
"cursor": "WyJwcmltYXJ5X2tleV9hc2MiLFs1XV0=",
1580+
"node": Object {
1581+
"boolean": null,
1582+
"id": 5,
1583+
"int": null,
1584+
"numeric": null,
1585+
"real": null,
1586+
"string": null,
1587+
},
1588+
},
1589+
],
1590+
"pageInfo": Object {
1591+
"endCursor": "WyJwcmltYXJ5X2tleV9hc2MiLFs1XV0=",
1592+
"hasNextPage": false,
1593+
"hasPreviousPage": false,
1594+
"startCursor": "WyJwcmltYXJ5X2tleV9hc2MiLFs1XV0=",
1595+
},
1596+
"totalCount": 1,
1597+
},
15211598
"string_likeInsensitive_es": Object {
15221599
"edges": Array [
15231600
Object {

__tests__/integration/__snapshots__/schema.test.js.snap

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ input AnIntFilter {
125125
# Checks for values in this list.
126126
in: [AnInt!]
127127

128+
# Checks for null or non-null values.
129+
is: NullOrNotNull
130+
128131
# Checks for values equal to this value, treating null like an ordinary value.
129132
notDistinctFrom: AnInt
130133

@@ -187,6 +190,9 @@ input AnotherIntFilter {
187190
# Checks for values in this list.
188191
in: [AnotherInt!]
189192

193+
# Checks for null or non-null values.
194+
is: NullOrNotNull
195+
190196
# Checks for values equal to this value, treating null like an ordinary value.
191197
notDistinctFrom: AnotherInt
192198

@@ -282,6 +288,9 @@ input BigFloatFilter {
282288
# Checks for values in this list.
283289
in: [BigFloat!]
284290

291+
# Checks for null or non-null values.
292+
is: NullOrNotNull
293+
285294
# Checks for values less than this value.
286295
lessThan: BigFloat
287296

@@ -353,6 +362,9 @@ input BigIntFilter {
353362
# Checks for values in this list.
354363
in: [BigInt!]
355364

365+
# Checks for null or non-null values.
366+
is: NullOrNotNull
367+
356368
# Checks for values equal to this value, treating null like an ordinary value.
357369
notDistinctFrom: BigInt
358370

@@ -377,6 +389,9 @@ input BooleanFilter {
377389
# Checks for values in this list.
378390
in: [Boolean!]
379391

392+
# Checks for null or non-null values.
393+
is: NullOrNotNull
394+
380395
# Checks for values equal to this value, treating null like an ordinary value.
381396
notDistinctFrom: Boolean
382397

@@ -407,6 +422,9 @@ input ColorFilter {
407422
# Checks for values in this list.
408423
in: [Color!]
409424

425+
# Checks for null or non-null values.
426+
is: NullOrNotNull
427+
410428
# Checks for values equal to this value, treating null like an ordinary value.
411429
notDistinctFrom: Color
412430

@@ -1040,6 +1058,9 @@ input DateFilter {
10401058
# Checks for values in this list.
10411059
in: [Date!]
10421060

1061+
# Checks for null or non-null values.
1062+
is: NullOrNotNull
1063+
10431064
# Checks for values less than this value.
10441065
lessThan: Date
10451066

@@ -1116,6 +1137,9 @@ input DatetimeFilter {
11161137
# Checks for values in this list.
11171138
in: [Datetime!]
11181139

1140+
# Checks for null or non-null values.
1141+
is: NullOrNotNull
1142+
11191143
# Checks for values less than this value.
11201144
lessThan: Datetime
11211145

@@ -1677,6 +1701,9 @@ input EmailFilter {
16771701
# Checks for values in this list.
16781702
in: [Email!]
16791703

1704+
# Checks for null or non-null values.
1705+
is: NullOrNotNull
1706+
16801707
# Checks for values equal to this value, treating null like an ordinary value.
16811708
notDistinctFrom: Email
16821709

@@ -1851,6 +1878,9 @@ input FloatFilter {
18511878
# Checks for values in this list.
18521879
in: [Float!]
18531880

1881+
# Checks for null or non-null values.
1882+
is: NullOrNotNull
1883+
18541884
# Checks for values less than this value.
18551885
lessThan: Float
18561886

@@ -2060,6 +2090,9 @@ input IntFilter {
20602090
# Checks for values in this list.
20612091
in: [Int!]
20622092

2093+
# Checks for null or non-null values.
2094+
is: NullOrNotNull
2095+
20632096
# Checks for values less than this value.
20642097
lessThan: Int
20652098

@@ -2191,6 +2224,9 @@ input JSONFilter {
21912224
# Checks for values in this list.
21922225
in: [JSON!]
21932226

2227+
# Checks for null or non-null values.
2228+
is: NullOrNotNull
2229+
21942230
# Checks for values equal to this value, treating null like an ordinary value.
21952231
notDistinctFrom: JSON
21962232

@@ -2862,6 +2898,11 @@ type NormalRandPayload {
28622898

28632899
scalar NotNullUrl
28642900

2901+
enum NullOrNotNull {
2902+
NOT_NULL
2903+
NULL
2904+
}
2905+
28652906
# Information about pagination in a connection.
28662907
type PageInfo {
28672908
# When paginating forwards, the cursor to continue.
@@ -4214,6 +4255,9 @@ input StringFilter {
42144255
# Checks for values in this list.
42154256
in: [String!]
42164257

4258+
# Checks for null or non-null values.
4259+
is: NullOrNotNull
4260+
42174261
# Checks for values less than this value.
42184262
lessThan: String
42194263

@@ -4522,6 +4566,9 @@ input TimeFilter {
45224566
# Checks for values in this list.
45234567
in: [Time!]
45244568

4569+
# Checks for null or non-null values.
4570+
is: NullOrNotNull
4571+
45254572
# Checks for values less than this value.
45264573
lessThan: Time
45274574

@@ -8264,6 +8311,9 @@ input BigFloatFilter {
82648311
# Checks for values in this list.
82658312
in: [BigFloat!]
82668313

8314+
# Checks for null or non-null values.
8315+
is: NullOrNotNull
8316+
82678317
# Checks for values less than this value.
82688318
lessThan: BigFloat
82698319

@@ -8294,6 +8344,9 @@ input BooleanFilter {
82948344
# Checks for values in this list.
82958345
in: [Boolean!]
82968346

8347+
# Checks for null or non-null values.
8348+
is: NullOrNotNull
8349+
82978350
# Checks for values not equal to this value.
82988351
ne: Boolean
82998352

@@ -9016,6 +9069,9 @@ input FloatFilter {
90169069
# Checks for values in this list.
90179070
in: [Float!]
90189071

9072+
# Checks for null or non-null values.
9073+
is: NullOrNotNull
9074+
90199075
# Checks for values less than this value.
90209076
lessThan: Float
90219077

@@ -9134,6 +9190,9 @@ input IntFilter {
91349190
# Checks for values in this list.
91359191
in: [Int!]
91369192

9193+
# Checks for null or non-null values.
9194+
is: NullOrNotNull
9195+
91379196
# Checks for values less than this value.
91389197
lessThan: Int
91399198

@@ -9479,6 +9538,11 @@ type NormalRandPayload {
94799538
query: Query
94809539
}
94819540

9541+
enum NullOrNotNull {
9542+
NOT_NULL
9543+
NULL
9544+
}
9545+
94829546
# Information about pagination in a connection.
94839547
type PageInfo {
94849548
# When paginating forwards, the cursor to continue.
@@ -10311,6 +10375,9 @@ input StringFilter {
1031110375
# Checks for values in this list.
1031210376
in: [String!]
1031310377

10378+
# Checks for null or non-null values.
10379+
is: NullOrNotNull
10380+
1031410381
# Checks for values less than this value.
1031510382
lessThan: String
1031610383

src/PgConnectionArgFilterOperatorsPlugin.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,40 @@ module.exports = function PgConnectionArgFilterOperatorsPlugin(builder) {
44
(
55
_,
66
{
7+
newWithHooks,
78
getTypeByName,
89
addConnectionFilterOperator,
910
escapeLikeWildcards,
1011
pgSql: sql,
11-
graphql: { GraphQLBoolean, GraphQLList, GraphQLNonNull },
12+
graphql: {
13+
GraphQLBoolean,
14+
GraphQLList,
15+
GraphQLNonNull,
16+
GraphQLEnumType,
17+
},
1218
}
1319
) => {
20+
addConnectionFilterOperator(
21+
"is",
22+
"Checks for null or non-null values.",
23+
() =>
24+
getTypeByName("NullOrNotNull") ||
25+
newWithHooks(
26+
GraphQLEnumType,
27+
{
28+
name: "NullOrNotNull",
29+
values: {
30+
NULL: { value: "NULL" },
31+
NOT_NULL: { value: "NOT NULL" },
32+
},
33+
},
34+
{}
35+
),
36+
(identifier, val, input) =>
37+
sql.query`${identifier} ${
38+
input === "NULL" ? sql.query`IS NULL` : sql.query`IS NOT NULL`
39+
}`
40+
);
1441
addConnectionFilterOperator(
1542
"null",
1643
"If set to true, checks for null values. If set to false, checks for non-null values.",

0 commit comments

Comments
 (0)