apoc.refactor.from

Procedure APOC Core

apoc.refactor.from(rel, startNode) redirect relationship to use new start-node

Signature

apoc.refactor.from(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 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;
Table 1. Results
input output

14

[: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: "Michael", city: "Dresden"})-[:FOLLOWS]→(:Person {name: "Jennifer", city: "St Louis"})