Skip to content

Commit

Permalink
Fix 7.x branch (#5896)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrellwarde authored Dec 16, 2024
1 parent c880a3c commit aa29046
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1,213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ import type { QueryASTContext } from "../QueryASTContext";
import { EntitySelection, type SelectionClause } from "./EntitySelection";

export class RelationshipSelection extends EntitySelection {
protected relationship: RelationshipAdapter;
private relationship: RelationshipAdapter;
// Overrides relationship target for composite entities
private targetOverride: ConcreteEntityAdapter | undefined;
private alias: string | undefined;
private directed?: boolean;
private optional: boolean;

constructor({
relationship,
alias,
directed,
targetOverride,
optional,
}: {
Expand All @@ -49,7 +47,6 @@ export class RelationshipSelection extends EntitySelection {
super();
this.relationship = relationship;
this.alias = alias;
this.directed = directed;
this.targetOverride = targetOverride;
this.optional = optional ?? false;
}
Expand All @@ -64,7 +61,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.getRelationshipDirection();
const relDirection = this.relationship.getCypherDirection();

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

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

/** Enforces direction on the relationship selection, regardless of direction configuration **/
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 @@ -66,7 +66,6 @@ export class AggregateFactory {

const selection = new RelationshipSelection({
relationship: entityOrRel,
directed: Boolean(resolveTree.args?.directed ?? true),
});

const operation = new AggregationOperation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class ConnectionFactory {
resolveTree: ResolveTree;
context: Neo4jGraphQLTranslationContext;
}): CompositeConnectionReadOperation {
const directed = resolveTree.args.directed as boolean | undefined;
const resolveTreeWhere: Record<string, any> = this.queryASTFactory.operationsFactory.getWhereArgs(resolveTree);

let nodeWhere: Record<string, any>;
Expand All @@ -85,7 +84,6 @@ export class ConnectionFactory {
if (relationship) {
selection = new RelationshipSelection({
relationship,
directed,
targetOverride: concreteEntity,
});
resolveTreeEdgeFields = this.parseConnectionFields({
Expand Down Expand Up @@ -165,7 +163,6 @@ export class ConnectionFactory {
if (relationship) {
selection = new RelationshipSelection({
relationship,
directed: resolveTree.args.directed as boolean | undefined,
});
resolveTreeEdgeFields = this.parseConnectionFields({
entityOrRel: relationship,
Expand Down Expand Up @@ -199,9 +196,8 @@ export class ConnectionFactory {
});
}

// eslint-disable-next-line @typescript-eslint/comma-dangle
private hydrateConnectionOperationsASTWithSort<
T extends ConnectionReadOperation | CompositeConnectionReadOperation
T extends ConnectionReadOperation | CompositeConnectionReadOperation,
>({
entityOrRel,
resolveTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 { DirectedRelationshipSelection } from "../../ast/selection/RelationshipSelection";
import { RelationshipSelection } 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 @@ -204,7 +204,7 @@ export class DeleteFactory {
context,
});

const selection = new DirectedRelationshipSelection({
const selection = new RelationshipSelection({
relationship,
optional: true,
targetOverride: target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export class ReadFactory {
if (relationship) {
selection = new RelationshipSelection({
relationship,
directed: Boolean(resolveTree.args?.directed ?? true),
});
} else {
selection = new NodeSelection({
Expand Down Expand Up @@ -105,7 +104,6 @@ export class ReadFactory {
if (relationship) {
selection = new RelationshipSelection({
relationship,
directed: Boolean(resolveTree.args?.directed ?? true),
targetOverride: concreteEntity,
});
} else {
Expand Down
Loading

0 comments on commit aa29046

Please sign in to comment.