apoc.refactor.invert

Details

Syntax

apoc.refactor.invert(rel) :: (input, output, error)

Description

Inverts the direction of the given RELATIONSHIP.

Input arguments

Name

Type

Description

rel

RELATIONSHIP

The relationship to reverse.

Return arguments

Name

Type

Description

input

INTEGER

The internal id of the original entity.

output

RELATIONSHIP

The copied entity.

error

STRING

Any error that occurred during the copy process.

Usage Examples

The examples in this section are based on the following sample graph:

CREATE (mark:Person {name: "Mark", city: "London"})
CREATE (jennifer:Person {name: "Jennifer", city: "St Louis"})
CREATE (michael:Person {name: "Michael", city: "Dresden"})
CREATE (mark)-[:FOLLOWS]->(jennifer);

The following makes Michael the start node in the FOLLOWS relationship:

MATCH (michael:Person {name: "Michael"})
MATCH ()-[rel:FOLLOWS]->()
CALL apoc.refactor.from(rel, michael)
YIELD input, output
RETURN input, output;
Results
input output

14

[:FOLLOWS]

We can list all the Person nodes by running the following query:

MATCH path = ()-[rel:FOLLOWS]->()
RETURN path;
Results
path

(:Person {name: "Michael", city: "Dresden"})-[:FOLLOWS]→(:Person {name: "Jennifer", city: "St Louis"})