Skip to content

Commit 6d264da

Browse files
authored
fix 6917 (#6920)
* add integration test * fix logical filters not translated in both edge and node
1 parent 72fa790 commit 6d264da

File tree

3 files changed

+370
-3
lines changed

3 files changed

+370
-3
lines changed

packages/graphql/src/translate/queryAST/factory/FilterFactory.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ export class FilterFactory {
480480
relationship?: RelationshipAdapter;
481481
}): Filter | Filter[] {
482482
const valueAsArray = asArray(value);
483+
if (key === "edge") {
484+
return [];
485+
}
483486
if (isLogicalOperator(key)) {
484487
const nestedFilters = valueAsArray.flatMap((nestedWhere) => {
485488
const nestedOfNestedFilters = Object.entries(nestedWhere).flatMap(([nestedKey, nestedValue]) => {
@@ -501,6 +504,16 @@ export class FilterFactory {
501504
filters: nestedFilters,
502505
});
503506
}
507+
if (key === "node") {
508+
const key = Object.keys(value)[0] as string;
509+
return this.parseEntryFilter({
510+
entity,
511+
key: Object.keys(value)[0] as string,
512+
value: value[key],
513+
targetEntity,
514+
relationship,
515+
});
516+
}
504517
const { fieldName, operator, isConnection, isAggregate } = parseWhereField(key);
505518
if (isConcreteEntity(entity)) {
506519
const relationship = entity.findRelationship(fieldName);
@@ -554,7 +567,6 @@ export class FilterFactory {
554567
if (!operator && !attribute.annotations.cypher?.targetEntity && typeof value === "object") {
555568
return this.parseGenericFilters(targetEntity ?? entity, fieldName, value, relationship);
556569
}
557-
558570
return this.createPropertyFilter({
559571
attribute,
560572
comparisonValue: value,
@@ -794,6 +806,9 @@ export class FilterFactory {
794806

795807
public createEdgeFilters(relationship: RelationshipAdapter, where: GraphQLWhereArg): Filter[] {
796808
const filterASTs = Object.entries(where).flatMap(([key, value]): Filter | Filter[] | undefined => {
809+
if (key === "node") {
810+
return [];
811+
}
797812
if (isLogicalOperator(key)) {
798813
const nestedFilters = asArray(value).flatMap((nestedWhere) => {
799814
return this.createEdgeFilters(relationship, nestedWhere);
@@ -803,6 +818,9 @@ export class FilterFactory {
803818
filters: nestedFilters,
804819
});
805820
}
821+
if (key === "edge") {
822+
return this.createEdgeFilters(relationship, value);
823+
}
806824
const { fieldName, operator } = parseWhereField(key);
807825

808826
const attribute = relationship.findAttribute(fieldName);

packages/graphql/src/translate/queryAST/factory/Operations/AggregateFactory.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,13 @@ export class AggregateFactory {
447447
);
448448
operation.addFilters(...nodeFilters, ...edgefilters);
449449
} else {
450-
const nodeFilters = this.queryASTFactory.filterFactory.createNodeFilters(entity, whereArgs.node ?? {}); // Aggregation filters only apply to target node
450+
const nodeFilters = this.queryASTFactory.filterFactory.createNodeFilters(
451+
entity,
452+
whereArgs.node ?? whereArgs ?? {}
453+
); // Aggregation filters only apply to target node
451454
const edgeFilters = this.queryASTFactory.filterFactory.createEdgeFilters(
452455
relationship,
453-
whereArgs.edge ?? {}
456+
whereArgs.edge ?? whereArgs ?? {}
454457
); // Aggregation filters only apply to target node
455458
operation.addFilters(...nodeFilters, ...edgeFilters);
456459

0 commit comments

Comments
 (0)