Virtual Nodes & Relationships (Graph Projections)

Virtual Nodes and Relationships do not exist in the graph, they are only returned by a query, and can be used to represent a graph projection.

They can be used to visually project data, for example aggregating relationships into one, or collapsing intermediate nodes into virtual relationships. We could project a citation graph into a virtual author-author or paper-paper graph with aggregated relationships between them, or even turn Twitter data into a user-user mention graph.

We can combine real and virtual entities, for example by creating a virtual relationship between two real nodes or creating a virtual relationship from a virtual node to a real node.

Working with Virtual Nodes

Virtual Nodes cannot be queried from the graph as they must be kept in a local lookup structure. This means that some built-in Cypher functions may not work. For example, using the /docs/cypher-manual/5/functions/list/#functions-labels[labels()^] function on a Virtual Node or Relationship will return an empty list [].

APOC provides functions that facilitate working with Virtual Nodes and Relationships.

Table 1. Functions
Qualified Name Type

apoc.any.properties
apoc.any.properties(object ANY, keys LIST<STRING>) - returns all properties of the given object. The object can be a virtual NODE, a real NODE, a virtual RELATIONSHIP, a real RELATIONSHIP, or a MAP.

Function

apoc.any.property
apoc.any.property(object ANY, key STRING) - returns the property for the given key from an object. The object can be a virtual NODE, a real NODE, a virtual RELATIONSHIP, a real RELATIONSHIP, or a MAP.

Function

apoc.map.groupBy
apoc.map.groupBy(values LIST<ANY>, key STRING) - creates a MAP of the LIST<ANY> keyed by the given property, with single values.

Function

apoc.node.id
apoc.node.id(node NODE) - returns the id for the given virtual NODE.

Function

apoc.node.labels
apoc.node.labels(node NODE) - returns the labels for the given virtual NODE.

Function

apoc.rel.endNode apoc.rel.endNode(rel RELATIONSHIP) - returns the end NODE for the given virtual RELATIONSHIP.

Function

apoc.rel.id apoc.rel.id(rel RELATIONSHIP) - returns the id for the given virtual RELATIONSHIP.

Function

apoc.rel.startNode apoc.rel.startNode(rel RELATIONSHIP) - returns the start NODE for the given virtual RELATIONSHIP.

Function

apoc.rel.type apoc.rel.type(rel RELATIONSHIP) - returns the type for the given virtual RELATIONSHIP.

Function

Virtual Nodes and Relationships have negative ids.

Virtual entities also have the following use cases:

  • Return only selected properties of nodes/relationships to the visualization (e.g. remove large or sensitive properties).

  • Visualize clusters found by graph algorithms.

  • Aggregate information to a higher level of abstraction.

  • Skip intermediate nodes in a longer path.

  • hide away properties or intermediate nodes/relationships for security reasons

  • graph grouping

  • visualization of data from other sources (computation, RDBMS, document-dbs, CSV, XML, JSON) as graph without even storing it

  • projecting partial data

For more information on how to use these procedures, see: