Skip to content

Commit 0255f77

Browse files
committed
Add names and optimize in/notIn exports
1 parent 5c5f919 commit 0255f77

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/PgConnectionArgFilterOperatorsPlugin.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
723723
},
724724
containsKey: {
725725
description: "Contains the specified key.",
726-
resolveInputCodec: EXPORTABLE((TYPES) => () => TYPES.text, [TYPES]),
726+
resolveInputCodec: EXPORTABLE(
727+
(TYPES) => () => TYPES.text,
728+
[TYPES],
729+
"resolveInputCodecText"
730+
),
727731
resolve: EXPORTABLE(
728732
(sql) => (i, v) => sql`${i} ? ${v}`,
729733
[sql],
@@ -853,16 +857,18 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
853857
? ([sourceAlias, codec] as const) // already case-insensitive, so no need to call `lower()`
854858
: ([sql`lower(${sourceAlias}::text)`, TYPES.text] as const);
855859
},
856-
[TYPES, resolveDomains, sql]
860+
[TYPES, resolveDomains, sql],
861+
"resolveSqlIdentifierInsensitiveOperator"
857862
);
863+
const inOrNotIn = name === "in" || name === "notIn";
858864
const resolveSqlValue = EXPORTABLE(
859-
(TYPES, name, sql, sqlValueWithCodec) =>
865+
(TYPES, inOrNotIn, sql, sqlValueWithCodec) =>
860866
function (
861867
_unused: unknown,
862868
input: any,
863869
inputCodec: PgCodec<any, any, any, any, any, any, any>
864870
) {
865-
if (name === "in" || name === "notIn") {
871+
if (inOrNotIn) {
866872
const sqlList = sqlValueWithCodec(input, inputCodec);
867873
if (inputCodec.arrayOfCodec === TYPES.citext) {
868874
// already case-insensitive, so no need to call `lower()`
@@ -883,15 +889,16 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
883889
}
884890
}
885891
},
886-
[TYPES, name, sql, sqlValueWithCodec]
892+
[TYPES, inOrNotIn, sql, sqlValueWithCodec],
893+
`resolveSqlValueInsensitiveOperator${inOrNotIn ? "_list" : ""}`
887894
);
888895

889896
const resolveInputCodec = EXPORTABLE(
890-
(TYPES, listOfCodec, name, resolveDomains) =>
897+
(TYPES, inOrNotIn, listOfCodec, resolveDomains) =>
891898
function (
892899
inputCodec: PgCodec<any, any, any, any, any, any, any>
893900
) {
894-
if (name === "in" || name === "notIn") {
901+
if (inOrNotIn) {
895902
const t =
896903
resolveDomains(inputCodec) === TYPES.citext
897904
? inputCodec
@@ -907,7 +914,8 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
907914
return t;
908915
}
909916
},
910-
[TYPES, listOfCodec, name, resolveDomains]
917+
[TYPES, inOrNotIn, listOfCodec, resolveDomains],
918+
`resolveInputCodecInsensitiveOperator${inOrNotIn ? "_list" : ""}`
911919
);
912920

913921
insensitiveOperators[`${name}Insensitive`] = {
@@ -950,7 +958,8 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
950958
);
951959
}
952960
},
953-
[]
961+
[],
962+
"resolveInputCodecContainsElement"
954963
),
955964
resolve: EXPORTABLE(
956965
(sql) => (i, v) => sql`${i} @> ${v}`,
@@ -1597,6 +1606,7 @@ export function makeApplyFromOperatorSpec(
15971606
resolveSqlValue,
15981607
sql,
15991608
sqlValueWithCodec,
1600-
]
1609+
],
1610+
"makeApplyFromOperatorSpec"
16011611
);
16021612
}

0 commit comments

Comments
 (0)