Collapse node to relationship

The available procedure is described in the table below:

call apoc.refactor.collapseNode([node1,node2],'TYPE')

collapse nodes with 2 rels to relationship, node with one rel becomes self-relationship

Example Usage

The example below will help us learn how to use this procedure.

The following creates a graph containing a Flight and origin and destination `Airport`s:
CREATE (flight:Flight {number: "BA001"})
CREATE (origin:Airport {code: "LHR"})
CREATE (destination:Airport {code: "AMS"})
CREATE (flight)<-[:OUT]-(origin)
CREATE (flight)-[:IN]->(destination)
apoc.refactor.collapseNode.dataset
The following query collapses the Flight node, replacing it with a CONNECTED to relationship:
MATCH (flight:Flight {number: "BA001"})
CALL apoc.refactor.collapseNode([flight],'CONNECTED_TO')
YIELD input, output , error
RETURN input, output, error

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

apoc.refactor.collapseNode