Skip to content

Commit 6f84d63

Browse files
committed
Fix the fieldName reference
1 parent 78b80e0 commit 6f84d63

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

.gitignore

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
node_modules
2-
dist
3-
.idea
1+
/.git
2+
/.idea
3+
/.yarn
4+
/.yarnrc.yml
5+
/dist
6+
/node_modules
7+
/Session.vim
8+
yarn-error.log

src/PgConnectionArgFilterAttributesPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export const PgConnectionArgFilterAttributesPlugin: GraphileConfig.Plugin = {
4141
) {
4242
continue;
4343
}
44-
const colSpec = { attributeName, attribute };
4544
const fieldName = inflection.attribute({ codec, attributeName });
45+
const colSpec = { fieldName, attributeName, attribute };
4646
const digest = connectionFilterOperatorsDigest(attribute.codec);
4747
if (!digest) {
4848
continue;

src/PgConnectionArgFilterComputedAttributesPlugin.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,7 @@ export const PgConnectionArgFilterComputedAttributesPlugin: GraphileConfig.Plugi
143143
description: `Filter by the object’s \`${fieldName}\` field.`,
144144
type: OperatorsType,
145145
applyPlan: EXPORTABLE(
146-
(
147-
PgConditionStep,
148-
computedAttributeResource,
149-
functionResultCodec
150-
) =>
151-
function (
146+
(PgConditionStep, computedAttributeResource, fieldName, functionResultCodec) => function (
152147
$where: PgConditionStep<any>,
153148
fieldArgs: FieldArgs
154149
) {
@@ -162,16 +157,13 @@ export const PgConnectionArgFilterComputedAttributesPlugin: GraphileConfig.Plugi
162157
});
163158
const $col = new PgConditionStep($where);
164159
$col.extensions.pgFilterAttribute = {
160+
fieldName,
165161
codec: functionResultCodec,
166162
expression,
167163
};
168164
fieldArgs.apply($col);
169165
},
170-
[
171-
PgConditionStep,
172-
computedAttributeResource,
173-
functionResultCodec,
174-
]
166+
[PgConditionStep, computedAttributeResource, fieldName, functionResultCodec]
175167
),
176168
}
177169
),

src/PgConnectionArgFilterOperatorsPlugin.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,8 @@ export interface OperatorSpec {
12161216
$placeholderable: PlaceholderableStep,
12171217
details: {
12181218
// TODO: move $input and $placeholderable here too
1219-
fieldName: string;
1219+
fieldName: string | null;
1220+
operatorName: string;
12201221
}
12211222
) => SQL;
12221223
resolveType?: (type: GraphQLInputType) => GraphQLInputType;
@@ -1288,8 +1289,13 @@ export function makeApplyPlanFromOperatorSpec(
12881289
if ($input.evalIs(undefined)) {
12891290
return;
12901291
}
1291-
const { attributeName, attribute, codec, expression } =
1292-
$where.extensions.pgFilterAttribute;
1292+
const {
1293+
fieldName: parentFieldName,
1294+
attributeName,
1295+
attribute,
1296+
codec,
1297+
expression,
1298+
} = $where.extensions.pgFilterAttribute;
12931299

12941300
const sourceAlias = attribute
12951301
? attribute.expression
@@ -1341,7 +1347,8 @@ export function makeApplyPlanFromOperatorSpec(
13411347
$where.placeholder($resolvedInput, inputCodec);
13421348

13431349
const fragment = resolve(sqlIdentifier, sqlValue, $input, $where, {
1344-
fieldName,
1350+
fieldName: parentFieldName ?? null,
1351+
operatorName: fieldName,
13451352
});
13461353
$where.where(fragment);
13471354
},

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ declare global {
2828
interface PgConditionStepExtensions {
2929
pgFilterAttribute?: /** Filtering a column */
3030
| {
31+
fieldName: string;
3132
attributeName: string;
3233
attribute: PgCodecAttribute;
3334
codec?: never;
3435
expression?: never;
3536
}
3637
| /** The incoming alias _is_ the column */ {
38+
fieldName?: string;
3739
attributeName?: never;
3840
attribute?: never;
3941
codec: PgCodec<any, any, any, any, any, any, any>;

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"sourceMap": true,
1010
"pretty": true
1111
},
12-
"include": ["src/**/*"]
12+
"include": ["src"]
1313
}

0 commit comments

Comments
 (0)