Extract node from relationships

The APOC library contains a procedure that can be used to create nodes from relationships.

Procedure for creating nodes from relationships

Qualified Name Type

apoc.refactor.extractNode(rels ANY, labels LIST<STRING>, outType STRING, inType STRING) - expands the given RELATIONSHIP VALUES into intermediate NODE VALUES. The intermediate NODE values are connected by the given outType and inType.

Procedure

Example

The example below will further explain this procedure.

The following creates a graph containing two nodes connected by a relationship:
CREATE (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar)
apoc.refactor.extractNode.dataset
The following converts the FOOBAR relationship into a node with label FOOBAR that has an incoming FOO relationship and outgoing BAR relationship:
MATCH (f:Foo)-[rel:FOOBAR {a:1}]->(b:Bar)
CALL apoc.refactor.extractNode(rel,['FooBar'],'FOO','BAR')
YIELD input, output
RETURN input, output

If the above query is run, it will result in the following graph:

apoc.refactor.extractNode