apoc.refactor.to

Procedure

apoc.refactor.to(rel RELATIONSHIP, endNode NODE) - redirects the given RELATIONSHIP to the given end NODE.

Signature

apoc.refactor.to(relationship :: RELATIONSHIP, newNode :: NODE) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)

Input parameters

Name Type Default

relationship

RELATIONSHIP

null

newNode

NODE

null

Output parameters

Name Type

input

INTEGER

output

RELATIONSHIP

error

STRING

Usage Examples

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

MERGE (person1:Person {name: "Michael"})
MERGE (person2:Person {name: "Ryan"})
MERGE (person3:Person {name: "Jennifer"})

MERGE (person1)-[:FRIENDS]->(person2);

The following makes Jennifer the end node in the FOLLOWS relationship instead of Ryan:

MATCH (:Person {name: "Michael"})-[rel:FRIENDS]->()
MATCH (jennifer:Person {name: "Jennifer"})
CALL apoc.refactor.to(rel, jennifer)
YIELD input, output
RETURN input, output;

If we execute this query, it will result in the following output:

Table 1. Results
input output

32

[:`FRIENDS`]

And the graph now looks like this:

apoc.refactor.to2