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 [String], outType String, inType String) - expands the given relationships into intermediate nodes. The intermediate nodes are connected by the given 'OUT' and 'IN' types.

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