Skip to content

Commit b4d6921

Browse files
committed
Fix logic in filter arg
1 parent ffa03ba commit b4d6921

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

src/PgConnectionArgFilterBackwardRelationsPlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
PgCodecWithAttributes,
55
PgRegistry,
66
PgResource,
7-
PgConditionCapableParent,
87
} from "@dataplan/pg";
98
import { makeAssertAllowed } from "./utils";
109
import { GraphQLInputObjectType } from "graphql";

src/PgConnectionArgFilterPlugin.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,12 @@ export const PgConnectionArgFilterPlugin: GraphileConfig.Plugin = {
403403

404404
// Add `filter` input argument to connection and simple collection types
405405
GraphQLObjectType_fields_field_args(args, build, context) {
406-
const { extend, inflection, EXPORTABLE } = build;
406+
const {
407+
extend,
408+
inflection,
409+
EXPORTABLE,
410+
dataplanPg: { PgCondition },
411+
} = build;
407412
const {
408413
scope: {
409414
isPgFieldConnection,
@@ -478,7 +483,7 @@ export const PgConnectionArgFilterPlugin: GraphileConfig.Plugin = {
478483
...(isPgFieldConnection
479484
? {
480485
applyPlan: EXPORTABLE(
481-
(assertAllowed, attributeCodec) =>
486+
(PgCondition, assertAllowed, attributeCodec) =>
482487
function (
483488
_: any,
484489
$connection: ConnectionStep<
@@ -489,49 +494,55 @@ export const PgConnectionArgFilterPlugin: GraphileConfig.Plugin = {
489494
>,
490495
fieldArg: FieldArg
491496
) {
492-
assertAllowed(fieldArg, "object");
493497
const $pgSelect = $connection.getSubplan();
494-
const myExtensions = attributeCodec
495-
? { pgFilterAttribute: { codec: attributeCodec } }
496-
: null;
497498
fieldArg.apply(
498499
$pgSelect,
499-
(queryBuilder: PgSelectQueryBuilder) => ({
500-
...queryBuilder,
501-
extensions: {
502-
...queryBuilder.extensions,
503-
...myExtensions,
504-
},
505-
})
500+
(
501+
queryBuilder: PgSelectQueryBuilder,
502+
value: object | null
503+
) => {
504+
assertAllowed(value, "object");
505+
if (value == null) return;
506+
const condition = new PgCondition(queryBuilder);
507+
if (attributeCodec) {
508+
condition.extensions.pgFilterAttribute = {
509+
codec: attributeCodec,
510+
};
511+
}
512+
return condition;
513+
}
506514
);
507515
},
508-
[assertAllowed, attributeCodec]
516+
[PgCondition, assertAllowed, attributeCodec]
509517
),
510518
}
511519
: {
512520
applyPlan: EXPORTABLE(
513-
(assertAllowed, attributeCodec) =>
521+
(PgCondition, assertAllowed, attributeCodec) =>
514522
function (
515523
_: any,
516524
$pgSelect: PgSelectStep,
517525
fieldArg: FieldArg
518526
) {
519-
assertAllowed(fieldArg, "object");
520-
const myExtensions = attributeCodec
521-
? { pgFilterAttribute: { codec: attributeCodec } }
522-
: null;
523527
fieldArg.apply(
524528
$pgSelect,
525-
(queryBuilder: PgSelectQueryBuilder) => ({
526-
...queryBuilder,
527-
extensions: {
528-
...queryBuilder.extensions,
529-
...myExtensions,
530-
},
531-
})
529+
(
530+
queryBuilder: PgSelectQueryBuilder,
531+
value: object | null
532+
) => {
533+
assertAllowed(value, "object");
534+
if (value == null) return;
535+
const condition = new PgCondition(queryBuilder);
536+
if (attributeCodec) {
537+
condition.extensions.pgFilterAttribute = {
538+
codec: attributeCodec,
539+
};
540+
}
541+
return condition;
542+
}
532543
);
533544
},
534-
[assertAllowed, attributeCodec]
545+
[PgCondition, assertAllowed, attributeCodec]
535546
),
536547
}),
537548
},

0 commit comments

Comments
 (0)