Redirect relationships

The available procedures are described in the table below:

Qualified Name Type Release

apoc.refactor.to

` apoc.refactor.to(rel, endNode) redirect relationship to use new end-node`

Procedure

APOC Core

apoc.refactor.from

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

Procedure

APOC Core

Example Usage

The examples below will help us learn how to use these procedures.

Redirect Target Node

The following creates Foo and Bar nodes that are connected by a FOOBAR relationship, as well as a solitary Antony node:
CREATE (f:Foo {value: "Foo"})-[rel:FOOBAR {a:1}]->(b:Bar {value: "Bar"})
CREATE (p:Person {name:'Antony'})
RETURN *
apoc.refactor.to.dataset
The following will change the target node of the FOOBAR relationship from the Bar node to the Antony node:
MATCH (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar)
MATCH (p:Person {name:'Antony'})
CALL apoc.refactor.to(rel, p)
YIELD input, output
RETURN input, output

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

apoc.refactor.to

Redirect Source Node

The following creates Foo2 and Bar2 nodes that are connected by a FOOBAR2 relationship, as well as a solitary David node:
CREATE (f:Foo2 {value: "Foo2"})-[rel:FOOBAR2 {a:1}]->(b:Bar2 {value: "Bar2"})
CREATE (p:Person {name:'David'})
RETURN *
apoc.refactor.from.dataset
The following will change the source node of the FOOBAR2 relationship from the Foo node to the David node:
MATCH (f:Foo2)-[rel:FOOBAR2 {a:1}]->(b:Bar2)
MATCH (p:Person {name:'David'})
CALL apoc.refactor.from(rel, p)
YIELD input, output
RETURN input, output

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

apoc.refactor.from