apoc.create.clonePathsToVirtual

This procedure returns virtual nodes and relationships that can only be accessed by other APOC procedures. For more information, see Virtual Nodes & Relationships (Graph Projections).
Details

Syntax

apoc.create.clonePathsToVirtual(paths) :: (path)

Description

Takes the given LIST<PATH> and returns a virtual representation of them.

Input arguments

Name

Type

Description

paths

LIST<PATH>

The paths to create virtual paths from.

Return arguments

Name

Type

Description

path

PATH

The path result.

Example

Given this dataset:

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

The following query collects multiple overlapping paths and returns a virtual clone of each:

MATCH p = (:Person {name: 'Alice'})-[:KNOWS*..2]->(:Person)
WITH collect(p) AS paths
CALL apoc.create.clonePathsToVirtual(paths) YIELD path
RETURN path AS virtualPath
Results
virtualPath

(:Person {name: "Alice"})-[:KNOWS]→(:Person {name: "Bob"})

(:Person {name: "Alice"})-[:KNOWS]→(:Person {name: "Bob"})-[:KNOWS]→(:Person {name: "Charlie"})

Both paths above share the Alice-[:KNOWS]→Bob relationship. Unlike calling apoc.create.clonePathToVirtual individually for each path, apoc.create.clonePathsToVirtual ensures that a relationship shared across multiple paths maps to the same virtual relationship object, avoiding duplication in the result.

The returned paths are virtual copies - any modifications made to their nodes or relationships do not affect the original graph data.