apoc.graph.from

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.graph.from(data, name, props) :: (graph)

Description

Generates a virtual sub-graph by extracting all of the NODE and RELATIONSHIP values from the given data.

Input arguments

Name

Type

Description

data

ANY

An object to extract nodes and relationships from. It can be of type; NODE | RELATIONSHIP | PATH | LIST<ANY>.

name

STRING

The name of the resulting graph.

props

MAP

The properties to be present in the resulting graph.

Return arguments

Name

Type

Description

graph

MAP

The resulting graph.

Usage Examples

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

CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
CREATE (JoelS:Person {name:'Joel Silver', born:1952})
CREATE
(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
(LillyW)-[:DIRECTED]->(TheMatrix),
(LanaW)-[:DIRECTED]->(TheMatrix),
(JoelS)-[:PRODUCED]->(TheMatrix);
MATCH (m:Movie)
WITH collect(m) AS movies
CALL apoc.graph.from(movies, "movies", {})
YIELD graph AS g
RETURN g;
Results
graph

{name: "movies", relationships: [], nodes: [(:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999})], properties: {}}