Skip to content

Commit 4dcd485

Browse files
authored
feat: overlaps operator for PG array columns (#71)
1 parent 02b18e7 commit 4dcd485

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

__tests__/fixtures/queries/connections-filter.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ query {
7272
intArray_containedBy_empty: allFilterables(filter: { intArray: { containedBy: [] } }) { ...intArrayConnection }
7373
intArray_containedBy_2: allFilterables(filter: { intArray: { containedBy: [2] } }) { ...intArrayConnection }
7474
intArray_containedBy_2_3_20: allFilterables(filter: { intArray: { containedBy: [2, 3, 20] } }) { ...intArrayConnection }
75+
intArray_overlaps_empty: allFilterables(filter: { intArray: { overlaps: [] } }) { ...intArrayConnection }
76+
intArray_overlaps_2: allFilterables(filter: { intArray: { overlaps: [2] } }) { ...intArrayConnection }
77+
intArray_overlaps_2_3_20: allFilterables(filter: { intArray: { overlaps: [2, 3, 20] } }) { ...intArrayConnection }
7578
intArray_anyEqualTo_2: allFilterables(filter: { intArray: { anyEqualTo: 2 } }) { ...intArrayConnection }
7679
intArray_anyNotEqualTo_2: allFilterables(filter: { intArray: { anyNotEqualTo: 2 } }) { ...intArrayConnection }
7780
intArray_anyLessThan_2: allFilterables(filter: { intArray: { anyLessThan: 2 } }) { ...intArrayConnection }

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,38 @@ Object {
798798
},
799799
],
800800
},
801+
"intArray_overlaps_2": Object {
802+
"nodes": Array [
803+
Object {
804+
"id": 2,
805+
"intArray": Array [
806+
2,
807+
20,
808+
],
809+
},
810+
],
811+
},
812+
"intArray_overlaps_2_3_20": Object {
813+
"nodes": Array [
814+
Object {
815+
"id": 2,
816+
"intArray": Array [
817+
2,
818+
20,
819+
],
820+
},
821+
Object {
822+
"id": 3,
823+
"intArray": Array [
824+
3,
825+
30,
826+
],
827+
},
828+
],
829+
},
830+
"intArray_overlaps_empty": Object {
831+
"nodes": Array [],
832+
},
801833
"int_equalTo_2_and_string_endsWith_t": Object {
802834
"nodes": Array [
803835
Object {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,9 @@ input IntListFilter {
953953
954954
\\"\\"\\"Not equal to the specified value.\\"\\"\\"
955955
notEqualTo: [Int]
956+
957+
\\"\\"\\"Overlaps the specified list of values.\\"\\"\\"
958+
overlaps: [Int]
956959
}
957960
958961
\\"\\"\\"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,9 @@ input IntListFilter {
953953
954954
\\"\\"\\"Equal to the specified value, treating null like an ordinary value.\\"\\"\\"
955955
notDistinctFrom: [Int]
956+
957+
\\"\\"\\"Overlaps the specified list of values.\\"\\"\\"
958+
overlaps: [Int]
956959
}
957960
958961
\\"\\"\\"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ input IntListFilter {
986986
987987
\\"\\"\\"Not equal to the specified value.\\"\\"\\"
988988
notEqualTo: [Int]
989+
990+
\\"\\"\\"Overlaps the specified list of values.\\"\\"\\"
991+
overlaps: [Int]
989992
}
990993
991994
\\"\\"\\"

src/PgConnectionArgFilterOperatorsPlugin.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,25 @@ module.exports = function PgConnectionArgFilterOperatorsPlugin(builder) {
373373
allowedListTypes: ["List"],
374374
}
375375
);
376+
addConnectionFilterOperator(
377+
"overlaps",
378+
"Overlaps the specified list of values.",
379+
fieldType => fieldType,
380+
(identifier, value) => sql.query`${identifier} && ${value}`,
381+
{
382+
allowedFieldTypes: [
383+
"String",
384+
"Int",
385+
"Float",
386+
"Datetime",
387+
"Date",
388+
"Time",
389+
"BigInt",
390+
"BigFloat",
391+
],
392+
allowedListTypes: ["List"],
393+
}
394+
);
376395
addConnectionFilterOperator(
377396
"anyEqualTo",
378397
"Any array item is equal to the specified value.",

0 commit comments

Comments
 (0)