apoc.refactor.extractNode

Procedure

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.

Signature

apoc.refactor.extractNode(relationships :: ANY, labels :: LIST<STRING>, outType :: STRING, inType :: STRING) :: (input :: INTEGER, output :: NODE, error :: STRING)

Input parameters

Name Type Default Description

rels

ANY

null

rels can be of type STRING (elementId()), INTEGER (id()), RELATIONSHIP or LIST<STRING | INTEGER | RELATIONSHIP>.

labels

LIST<STRING>

null

The labels to be added to the new NODE values.

outType

STRING

null

The type of the RELATIONSHIP value which will be outgoing from the new NODE value.

inType

STRING

null

The type of the RELATIONSHIP value which will be incoming to the new NODE value.

Output parameters

Name Type

input

INTEGER

output

NODE

error

STRING

Usage Examples

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

CREATE (origin:Airport {code: "LHR"})
CREATE (destination:Airport {code: "AMS"})
CREATE (origin)-[:FLIGHT {number: "BA001"}]->(destination);

The following creates a Flight node with an IN relationship from LHR and an OUT relationship to AMS:

MATCH (:Airport)-[rel:FLIGHT]->(:Airport)
WITH collect(rel) AS rels
CALL apoc.refactor.extractNode(rels,['Flight'],'OUT','IN')
YIELD input, output
RETURN input, output;
Table 1. Results
input output

0

(:Flight {number: "BA001"})

We can list all the Flight nodes by running the following query:

MATCH path = (origin)-[:IN]->(:Flight)-[:OUT]->(destination)
RETURN path;
Table 2. Results
path

(:Airport {code: "LHR"})-[:IN]→(:Flight {number: "BA001"})-[:OUT]→(:Airport {code: "AMS"})