Skip to content

Commit

Permalink
queryDirection fixes for LTS (#5889)
Browse files Browse the repository at this point in the history
* Fix queryDirection interpretation for nested delete

* Add integration tests

* Test modifications for LTS branch
  • Loading branch information
darrellwarde authored Dec 16, 2024
1 parent d2d7756 commit b125790
Show file tree
Hide file tree
Showing 5 changed files with 2,340 additions and 142 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-months-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Fix incorrect relationship direction when performing a delete operation nested under a delete operation
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { QueryASTContext } from "../QueryASTContext";
import { EntitySelection, type SelectionClause } from "./EntitySelection";

export class RelationshipSelection extends EntitySelection {
private relationship: RelationshipAdapter;
protected relationship: RelationshipAdapter;
// Overrides relationship target for composite entities
private targetOverride: ConcreteEntityAdapter | undefined;
private alias: string | undefined;
Expand Down Expand Up @@ -64,7 +64,7 @@ export class RelationshipSelection extends EntitySelection {
const relationshipTarget = this.targetOverride ?? this.relationship.target;
const targetNode = createNode(this.alias);
const labels = getEntityLabels(relationshipTarget, context.neo4jGraphQLContext);
const relDirection = this.relationship.getCypherDirection(this.directed);
const relDirection = this.getRelationshipDirection();

const pattern = new Cypher.Pattern(context.target)
.related(relVar, { direction: relDirection, type: this.relationship.type })
Expand All @@ -81,4 +81,14 @@ export class RelationshipSelection extends EntitySelection {
selection: match,
};
}

protected getRelationshipDirection(): "left" | "right" | "undirected" {
return this.relationship.getCypherDirection(this.directed);
}
}

export class DirectedRelationshipSelection extends RelationshipSelection {
protected getRelationshipDirection(): "left" | "right" {
return this.relationship.cypherDirectionFromRelDirection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { checkEntityAuthentication } from "../../../authorization/check-authenti
import type { Filter } from "../../ast/filters/Filter";
import { DeleteOperation } from "../../ast/operations/DeleteOperation";
import { NodeSelection } from "../../ast/selection/NodeSelection";
import { RelationshipSelection } from "../../ast/selection/RelationshipSelection";
import { DirectedRelationshipSelection } from "../../ast/selection/RelationshipSelection";
import { getConcreteEntities } from "../../utils/get-concrete-entities";
import { isInterfaceEntity } from "../../utils/is-interface-entity";
import { isUnionEntity } from "../../utils/is-union-entity";
Expand Down Expand Up @@ -205,9 +205,8 @@ export class DeleteFactory {
context,
});

const selection = new RelationshipSelection({
const selection = new DirectedRelationshipSelection({
relationship,
directed: true,
optional: true,
targetOverride: target,
});
Expand Down
Loading

0 comments on commit b125790

Please sign in to comment.