Skip to content

Commit

Permalink
Fix #206, add missing exportables
Browse files Browse the repository at this point in the history
  • Loading branch information
mattia rossi committed Feb 3, 2024
1 parent ac8c5c1 commit 3ff7f69
Showing 1 changed file with 57 additions and 15 deletions.
72 changes: 57 additions & 15 deletions src/PgConnectionArgFilterOperatorsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
[TYPES]
),
resolveSqlValue: EXPORTABLE((sql) => () => sql.null, [sql]), // do not parse
resolve: (i, _v, $input) =>
sql`${i} ${$input.eval() ? sql`IS NULL` : sql`IS NOT NULL`}`,
resolve: EXPORTABLE(
(sql) => (i, _v, $input) =>
sql`${i} ${$input.eval() ? sql`IS NULL` : sql`IS NOT NULL`}`,
[sql]
),
},
equalTo: {
description: "Equal to the specified value.",
Expand Down Expand Up @@ -383,7 +386,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
notIncludesInsensitive: {
description:
"Does not contain the specified string (case-insensitive).",
resolveInput: (input) => `%${escapeLikeWildcards(input)}%`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`%${escapeLikeWildcards(input)}%`,
[escapeLikeWildcards]
),
resolve: EXPORTABLE(
(sql) => (i, v) => sql`${i} NOT ILIKE ${v}`,
[sql]
Expand All @@ -393,7 +400,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
},
startsWith: {
description: "Starts with the specified string (case-sensitive).",
resolveInput: (input) => `${escapeLikeWildcards(input)}%`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`${escapeLikeWildcards(input)}%`,
[escapeLikeWildcards]
),
resolveInputCodec: resolveInputCodecSensitive,
resolveSqlIdentifier: resolveSqlIdentifierSensitive,
resolve: EXPORTABLE(
Expand All @@ -404,7 +415,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
notStartsWith: {
description:
"Does not start with the specified string (case-sensitive).",
resolveInput: (input) => `${escapeLikeWildcards(input)}%`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`${escapeLikeWildcards(input)}%`,
[escapeLikeWildcards]
),
resolveInputCodec: resolveInputCodecSensitive,
resolveSqlIdentifier: resolveSqlIdentifierSensitive,
resolve: EXPORTABLE(
Expand All @@ -415,7 +430,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
startsWithInsensitive: {
description:
"Starts with the specified string (case-insensitive).",
resolveInput: (input) => `${escapeLikeWildcards(input)}%`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`${escapeLikeWildcards(input)}%`,
[escapeLikeWildcards]
),
resolve: EXPORTABLE(
(sql) => (i, v) => sql`${i} ILIKE ${v}`,
[sql]
Expand All @@ -426,7 +445,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
notStartsWithInsensitive: {
description:
"Does not start with the specified string (case-insensitive).",
resolveInput: (input) => `${escapeLikeWildcards(input)}%`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`${escapeLikeWildcards(input)}%`,
[escapeLikeWildcards]
),
resolve: EXPORTABLE(
(sql) => (i, v) => sql`${i} NOT ILIKE ${v}`,
[sql]
Expand All @@ -436,7 +459,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
},
endsWith: {
description: "Ends with the specified string (case-sensitive).",
resolveInput: (input) => `%${escapeLikeWildcards(input)}`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`%${escapeLikeWildcards(input)}`,
[escapeLikeWildcards]
),
resolveInputCodec: resolveInputCodecSensitive,
resolveSqlIdentifier: resolveSqlIdentifierSensitive,
resolve: EXPORTABLE(
Expand All @@ -447,7 +474,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
notEndsWith: {
description:
"Does not end with the specified string (case-sensitive).",
resolveInput: (input) => `%${escapeLikeWildcards(input)}`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`%${escapeLikeWildcards(input)}`,
[escapeLikeWildcards]
),
resolveInputCodec: resolveInputCodecSensitive,
resolveSqlIdentifier: resolveSqlIdentifierSensitive,
resolve: EXPORTABLE(
Expand All @@ -457,7 +488,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
},
endsWithInsensitive: {
description: "Ends with the specified string (case-insensitive).",
resolveInput: (input) => `%${escapeLikeWildcards(input)}`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`%${escapeLikeWildcards(input)}`,
[escapeLikeWildcards]
),
resolve: EXPORTABLE(
(sql) => (i, v) => sql`${i} ILIKE ${v}`,
[sql]
Expand All @@ -468,7 +503,11 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
notEndsWithInsensitive: {
description:
"Does not end with the specified string (case-insensitive).",
resolveInput: (input) => `%${escapeLikeWildcards(input)}`,
resolveInput: EXPORTABLE(
(escapeLikeWildcards) => (input) =>
`%${escapeLikeWildcards(input)}`,
[escapeLikeWildcards]
),
resolve: EXPORTABLE(
(sql) => (i, v) => sql`${i} NOT ILIKE ${v}`,
[sql]
Expand Down Expand Up @@ -517,16 +556,19 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
resolveSqlIdentifier: resolveSqlIdentifierInsensitive,
},
};
const resolveTextArrayInputCodec = () =>
listOfCodec(TYPES.text, { extensions: { listItemNonNull: true } });
const resolveTextArrayInputCodec = EXPORTABLE(
(TYPES, listOfCodec) => () =>
listOfCodec(TYPES.text, { extensions: { listItemNonNull: true } }),
[TYPES, listOfCodec]
);
const hstoreOperators: { [fieldName: string]: OperatorSpec } = {
contains: {
description: "Contains the specified KeyValueHash.",
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} @> ${v}`, [sql]),
},
containsKey: {
description: "Contains the specified key.",
resolveInputCodec: () => TYPES.text,
resolveInputCodec: EXPORTABLE((TYPES) => () => TYPES.text, [TYPES]),
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} ? ${v}`, [sql]),
},
containsAllKeys: {
Expand Down Expand Up @@ -555,7 +597,7 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
},
containsKey: {
description: "Contains the specified key.",
resolveInputCodec: () => TYPES.text,
resolveInputCodec: EXPORTABLE((TYPES) => () => TYPES.text, [TYPES]),
resolve: EXPORTABLE((sql) => (i, v) => sql`${i} ? ${v}`, [sql]),
},
containsAllKeys: {
Expand Down

0 comments on commit 3ff7f69

Please sign in to comment.