Skip to content

Commit

Permalink
Fix the fieldName reference
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Nov 25, 2024
1 parent 78b80e0 commit 6f84d63
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
node_modules
dist
.idea
/.git
/.idea
/.yarn
/.yarnrc.yml
/dist
/node_modules
/Session.vim
yarn-error.log
2 changes: 1 addition & 1 deletion src/PgConnectionArgFilterAttributesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const PgConnectionArgFilterAttributesPlugin: GraphileConfig.Plugin = {
) {
continue;
}
const colSpec = { attributeName, attribute };
const fieldName = inflection.attribute({ codec, attributeName });
const colSpec = { fieldName, attributeName, attribute };
const digest = connectionFilterOperatorsDigest(attribute.codec);
if (!digest) {
continue;
Expand Down
14 changes: 3 additions & 11 deletions src/PgConnectionArgFilterComputedAttributesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ export const PgConnectionArgFilterComputedAttributesPlugin: GraphileConfig.Plugi
description: `Filter by the object’s \`${fieldName}\` field.`,
type: OperatorsType,
applyPlan: EXPORTABLE(
(
PgConditionStep,
computedAttributeResource,
functionResultCodec
) =>
function (
(PgConditionStep, computedAttributeResource, fieldName, functionResultCodec) => function (
$where: PgConditionStep<any>,
fieldArgs: FieldArgs
) {
Expand All @@ -162,16 +157,13 @@ export const PgConnectionArgFilterComputedAttributesPlugin: GraphileConfig.Plugi
});
const $col = new PgConditionStep($where);
$col.extensions.pgFilterAttribute = {
fieldName,
codec: functionResultCodec,
expression,
};
fieldArgs.apply($col);
},
[
PgConditionStep,
computedAttributeResource,
functionResultCodec,
]
[PgConditionStep, computedAttributeResource, fieldName, functionResultCodec]
),
}
),
Expand Down
15 changes: 11 additions & 4 deletions src/PgConnectionArgFilterOperatorsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,8 @@ export interface OperatorSpec {
$placeholderable: PlaceholderableStep,
details: {
// TODO: move $input and $placeholderable here too
fieldName: string;
fieldName: string | null;
operatorName: string;
}
) => SQL;
resolveType?: (type: GraphQLInputType) => GraphQLInputType;
Expand Down Expand Up @@ -1288,8 +1289,13 @@ export function makeApplyPlanFromOperatorSpec(
if ($input.evalIs(undefined)) {
return;
}
const { attributeName, attribute, codec, expression } =
$where.extensions.pgFilterAttribute;
const {
fieldName: parentFieldName,
attributeName,
attribute,
codec,
expression,
} = $where.extensions.pgFilterAttribute;

const sourceAlias = attribute
? attribute.expression
Expand Down Expand Up @@ -1341,7 +1347,8 @@ export function makeApplyPlanFromOperatorSpec(
$where.placeholder($resolvedInput, inputCodec);

const fragment = resolve(sqlIdentifier, sqlValue, $input, $where, {
fieldName,
fieldName: parentFieldName ?? null,
operatorName: fieldName,
});
$where.where(fragment);
},
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ declare global {
interface PgConditionStepExtensions {
pgFilterAttribute?: /** Filtering a column */
| {
fieldName: string;
attributeName: string;
attribute: PgCodecAttribute;
codec?: never;
expression?: never;
}
| /** The incoming alias _is_ the column */ {
fieldName?: string;
attributeName?: never;
attribute?: never;
codec: PgCodec<any, any, any, any, any, any, any>;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"sourceMap": true,
"pretty": true
},
"include": ["src/**/*"]
"include": ["src"]
}

0 comments on commit 6f84d63

Please sign in to comment.