apoc.refactor.collapseNode

Procedure APOC Core

apoc.refactor.collapseNode([node1,node2],'TYPE') collapse node to relationship, node with one rel becomes self-relationship

Signature

apoc.refactor.collapseNode(nodes :: ANY?, type :: STRING?) :: (input :: INTEGER?, output :: RELATIONSHIP?, error :: STRING?)

Input parameters

Name Type Default

nodes

ANY?

null

type

STRING?

null

Output parameters

Name Type

input

INTEGER?

output

RELATIONSHIP?

error

STRING?

Usage Examples

The examples in this section are based on the following sample graph:

CREATE (flight:Flight {number: "BA001"})
CREATE (origin:Airport {code: "LHR"})
CREATE (destination:Airport {code: "AMS"})
CREATE (flight)<-[:OUT]-(origin)
CREATE (flight)-[:IN]->(destination);

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
RETURN input, output;
Table 1. Results
input output

10

[:CONNECTED_TO {number: "BA001"}]

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

apoc.refactor.collapseNode