Skip to content

Commit d6f00e9

Browse files
committed
Cache arrays so export can deduplicate
1 parent 888ca05 commit d6f00e9

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

src/PgConnectionArgFilterOperatorsPlugin.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
import type {
77
GrafastInputFieldConfigMap,
88
InputObjectFieldApplyResolver,
9-
Step,
109
} from "grafast";
1110
import type { GraphQLInputType, GraphQLNamedType } from "graphql";
1211
import type { SQL } from "pg-sql2";
@@ -16,12 +15,40 @@ import { version } from "./version";
1615

1716
// const textArrayCodec = listOfCodec(TYPES.text);
1817

18+
declare global {
19+
namespace GraphileBuild {
20+
interface Build {
21+
pgAggregatesForceTextTypesInsensitive: PgCodec[];
22+
pgAggregatesForceTextTypesSensitive: PgCodec[];
23+
}
24+
}
25+
}
26+
1927
export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
2028
name: "PgConnectionArgFilterOperatorsPlugin",
2129
version,
30+
after: ["PgBasicsPlugin"],
2231

2332
schema: {
2433
hooks: {
34+
build(build) {
35+
if (!build.dataplanPg) {
36+
throw new Error("Must be loaded after dataplanPg is added to build");
37+
}
38+
const { TYPES } = build.dataplanPg;
39+
return build.extend(
40+
build,
41+
{
42+
pgAggregatesForceTextTypesInsensitive: [TYPES.char, TYPES.bpchar],
43+
pgAggregatesForceTextTypesSensitive: [
44+
TYPES.citext,
45+
TYPES.char,
46+
TYPES.bpchar,
47+
],
48+
},
49+
"Adding text types that need to be forced to be case sensitive"
50+
);
51+
},
2552
GraphQLInputObjectType_fields(fields, build, context) {
2653
const {
2754
extend,
@@ -34,6 +61,8 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
3461
connectionFilterOperatorNames,
3562
},
3663
EXPORTABLE,
64+
pgAggregatesForceTextTypesSensitive: forceTextTypesSensitive,
65+
pgAggregatesForceTextTypesInsensitive: forceTextTypesInsensitive,
3766
} = build;
3867

3968
const {
@@ -78,12 +107,6 @@ export const PgConnectionArgFilterOperatorsPlugin: GraphileConfig.Plugin = {
78107
"resolveTypeToListOfNonNullable"
79108
);
80109

81-
const forceTextTypesSensitive = [
82-
TYPES.citext,
83-
TYPES.char,
84-
TYPES.bpchar,
85-
];
86-
const forceTextTypesInsensitive = [TYPES.char, TYPES.bpchar];
87110
const resolveDomains = EXPORTABLE(
88111
() =>
89112
function (

0 commit comments

Comments
 (0)