apoc.refactor.setType
Syntax |
|
||
Description |
Changes the type of the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The relationship to change the type of. |
|
|
|
The new type for the relationship. |
|
Return arguments |
Name |
Type |
Description |
|
|
The id of the given relationship. |
|
|
|
The id of the new relationship with the updated type. |
|
|
|
The message if an error occurred. |
Refactoring nodes using Cypher
Node labels and relationship types can be referenced dynamically in Cypher without using APOC.
CREATE (n1:$(label))-[r:$(type)]->(n2:$(label))
MERGE (n1:$(label))-[r:$(type)]->(n2:$(label))
MATCH (n1:$(label))-[r:$(type)]->(n2:$(label))
The dynamically calculated type must evaluate to a STRING
or LIST<STRING>
.
For more information, see the Cypher Manual → CREATE,
MERGE, MATCH.
Usage Examples
The examples in this section are based on the following graph:
CREATE (f:Foo)-[rel:FOOBAR]->(b:Bar);
The following queries change the relationship type from FOOBAR
to NEW-TYPE
using APOC and Cypher:
MATCH (f:Foo)-[rel:FOOBAR]->(b:Bar)
CALL apoc.refactor.setType(rel, 'NEW-TYPE')
YIELD input, output
RETURN input, output;
MATCH (f:Foo)-[rel:FOOBAR]->(b:Bar)
CREATE (f)-[r:`NEW-TYPE`]->(b)
SET r = properties(rel)
DELETE rel
RETURN id(r), type(r)
If we execute this query, it will result in the following output:
input | output |
---|---|
30 |
[:`NEW-TYPE`] |
And the graph now looks like this:

APOC is not inverting the type; instead, it adds a new relationship with the desired direction and deletes the original. |