apoc.refactor.from

Details

Syntax

apoc.refactor.from(rel, newNode) :: (input, output, error)

Description

Redirects the given RELATIONSHIP to the given start NODE.

Input arguments

Name

Type

Description

rel

RELATIONSHIP

The relationship to redirect.

newNode

NODE

The node to redirect the given relationship to.

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"})