Skip to content

Commit 110f7bf

Browse files
authored
feat: containment operators for PG array columns (#70)
1 parent 9ae4c18 commit 110f7bf

File tree

6 files changed

+125
-0
lines changed

6 files changed

+125
-0
lines changed

__tests__/fixtures/queries/connections-filter.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ query {
6666
intArray_greaterThan_empty: allFilterables(filter: { intArray: { greaterThan: [] } }) { ...intArrayConnection }
6767
intArray_greaterThanOrEqualTo_2_20: allFilterables(filter: { intArray: { greaterThanOrEqualTo: [2, 20] } }) { ...intArrayConnection }
6868
intArray_greaterThanOrEqualTo_empty: allFilterables(filter: { intArray: { greaterThanOrEqualTo: [] } }) { ...intArrayConnection }
69+
intArray_contains_empty: allFilterables(filter: { intArray: { contains: [] } }) { ...intArrayConnection }
70+
intArray_contains_2: allFilterables(filter: { intArray: { contains: [2] } }) { ...intArrayConnection }
71+
intArray_contains_2_3_20: allFilterables(filter: { intArray: { contains: [2, 3, 20] } }) { ...intArrayConnection }
72+
intArray_containedBy_empty: allFilterables(filter: { intArray: { containedBy: [] } }) { ...intArrayConnection }
73+
intArray_containedBy_2: allFilterables(filter: { intArray: { containedBy: [2] } }) { ...intArrayConnection }
74+
intArray_containedBy_2_3_20: allFilterables(filter: { intArray: { containedBy: [2, 3, 20] } }) { ...intArrayConnection }
6975
intArray_anyEqualTo_2: allFilterables(filter: { intArray: { anyEqualTo: 2 } }) { ...intArrayConnection }
7076
intArray_anyNotEqualTo_2: allFilterables(filter: { intArray: { anyNotEqualTo: 2 } }) { ...intArrayConnection }
7177
intArray_anyLessThan_2: allFilterables(filter: { intArray: { anyLessThan: 2 } }) { ...intArrayConnection }

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,69 @@ Object {
403403
},
404404
],
405405
},
406+
"intArray_containedBy_2": Object {
407+
"nodes": Array [],
408+
},
409+
"intArray_containedBy_2_3_20": Object {
410+
"nodes": Array [
411+
Object {
412+
"id": 2,
413+
"intArray": Array [
414+
2,
415+
20,
416+
],
417+
},
418+
],
419+
},
420+
"intArray_containedBy_empty": Object {
421+
"nodes": Array [],
422+
},
423+
"intArray_contains_2": Object {
424+
"nodes": Array [
425+
Object {
426+
"id": 2,
427+
"intArray": Array [
428+
2,
429+
20,
430+
],
431+
},
432+
],
433+
},
434+
"intArray_contains_2_3_20": Object {
435+
"nodes": Array [],
436+
},
437+
"intArray_contains_empty": Object {
438+
"nodes": Array [
439+
Object {
440+
"id": 1,
441+
"intArray": Array [
442+
1,
443+
10,
444+
],
445+
},
446+
Object {
447+
"id": 2,
448+
"intArray": Array [
449+
2,
450+
20,
451+
],
452+
},
453+
Object {
454+
"id": 3,
455+
"intArray": Array [
456+
3,
457+
30,
458+
],
459+
},
460+
Object {
461+
"id": 4,
462+
"intArray": Array [
463+
4,
464+
40,
465+
],
466+
},
467+
],
468+
},
406469
"intArray_distinctFrom_2_20": Object {
407470
"nodes": Array [
408471
Object {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,12 @@ input IntListFilter {
917917
\\"\\"\\"Any array item is not equal to the specified value.\\"\\"\\"
918918
anyNotEqualTo: Int
919919
920+
\\"\\"\\"Contained by the specified list of values.\\"\\"\\"
921+
containedBy: [Int]
922+
923+
\\"\\"\\"Contains the specified list of values.\\"\\"\\"
924+
contains: [Int]
925+
920926
\\"\\"\\"
921927
Not equal to the specified value, treating null like an ordinary value.
922928
\\"\\"\\"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,12 @@ input IntListFilter {
917917
\\"\\"\\"Any array item is not equal to the specified value.\\"\\"\\"
918918
anyNotEqualTo: Int
919919
920+
\\"\\"\\"Contained by the specified list of values.\\"\\"\\"
921+
containedBy: [Int]
922+
923+
\\"\\"\\"Contains the specified list of values.\\"\\"\\"
924+
contains: [Int]
925+
920926
\\"\\"\\"
921927
Not equal to the specified value, treating null like an ordinary value.
922928
\\"\\"\\"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,12 @@ input IntListFilter {
950950
\\"\\"\\"Any array item is not equal to the specified value.\\"\\"\\"
951951
anyNotEqualTo: Int
952952
953+
\\"\\"\\"Contained by the specified list of values.\\"\\"\\"
954+
containedBy: [Int]
955+
956+
\\"\\"\\"Contains the specified list of values.\\"\\"\\"
957+
contains: [Int]
958+
953959
\\"\\"\\"
954960
Not equal to the specified value, treating null like an ordinary value.
955961
\\"\\"\\"

src/PgConnectionArgFilterOperatorsPlugin.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,44 @@ module.exports = function PgConnectionArgFilterOperatorsPlugin(builder) {
335335
allowedFieldTypes: ["JSON"],
336336
}
337337
);
338+
addConnectionFilterOperator(
339+
"contains",
340+
"Contains the specified list of values.",
341+
fieldType => fieldType,
342+
(identifier, value) => sql.query`${identifier} @> ${value}`,
343+
{
344+
allowedFieldTypes: [
345+
"String",
346+
"Int",
347+
"Float",
348+
"Datetime",
349+
"Date",
350+
"Time",
351+
"BigInt",
352+
"BigFloat",
353+
],
354+
allowedListTypes: ["List"],
355+
}
356+
);
357+
addConnectionFilterOperator(
358+
"containedBy",
359+
"Contained by the specified list of values.",
360+
fieldType => fieldType,
361+
(identifier, value) => sql.query`${identifier} <@ ${value}`,
362+
{
363+
allowedFieldTypes: [
364+
"String",
365+
"Int",
366+
"Float",
367+
"Datetime",
368+
"Date",
369+
"Time",
370+
"BigInt",
371+
"BigFloat",
372+
],
373+
allowedListTypes: ["List"],
374+
}
375+
);
338376
addConnectionFilterOperator(
339377
"anyEqualTo",
340378
"Any array item is equal to the specified value.",

0 commit comments

Comments
 (0)