apoc.refactor.to

Details

Syntax

apoc.refactor.to(rel, endNode) :: (input, output, error)

Description

Redirects the given RELATIONSHIP to the given end NODE.

Input arguments

Name

Type

Description

rel

RELATIONSHIP

The relationship to redirect.

endNode

NODE

The new end node the relationship should point to.

Return arguments

Name

Type

Description

input

INTEGER

The id of the given relationship.

output

RELATIONSHIP

The id of the new relationship with the updated type.

error

STRING

The message if an error occurred.

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:

Results
input output

32

[:`FRIENDS`]

And the graph now looks like this:

apoc.refactor.to2