apoc.refactor.invert

Procedure

apoc.refactor.invert(rel RELATIONSHIP) - inverts the direction of the given RELATIONSHIP.

Signature

apoc.refactor.invert(relationship :: RELATIONSHIP) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)

Input parameters

Name Type Default

relationship

RELATIONSHIP

null

Output parameters

Name Type

input

INTEGER

output

RELATIONSHIP

error

STRING

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 (mark)-[:FOLLOWS]->(jennifer);

The following reverses the direction of the FOLLOWS relationship:

MATCH ()-[rel:FOLLOWS]->()
CALL apoc.refactor.invert(rel)
YIELD input, output
RETURN input, output;
Table 1. Results
input output

0

[:FOLLOWS]

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

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

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