apoc.convert.toRelationship

Details

Syntax

apoc.convert.toRelationship(rel)

Description

Converts the given value into a RELATIONSHIP.

Arguments

Name

Type

Description

rel

ANY

The value to convert into a relationship.

Returns

RELATIONSHIP

Example

Given this dataset:

CREATE (:Person {name: 'Alice'})-[:KNOWS {since: 2020}]->(:Person {name: 'Bob'})

The following query uses apoc.convert.toRelationship to cast a value extracted from a generic list back to a RELATIONSHIP:

MATCH ()-[r:KNOWS]->()
WITH collect(r) AS rels
RETURN apoc.convert.toRelationship(rels[0]) AS rel
Results
rel

[:KNOWS {since: 2020}]

The function returns null when passed null or a value that is not a RELATIONSHIP:

RETURN apoc.convert.toRelationship(null) AS nullInput,
     apoc.convert.toRelationship('not a rel') AS wrongType
Results
nullInput wrongType

null

null