apoc.graph.fromCypher
Procedure
apoc.graph.fromCypher(statement STRING, params MAP<STRING, ANY>, name STRING, props MAP<STRING, ANY>)
- generates a virtual sub-graph by extracting all of the NODE
and RELATIONSHIP
values from the data returned by the given Cypher statement.
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). |
This procedure is not considered safe to run from multiple threads. It is therefore not supported by the parallel runtime (introduced in Neo4j 5.13). For more information, see the Cypher Manual → Parallel runtime. |
Signature
apoc.graph.fromCypher(kernelTransaction :: STRING, params :: MAP, name :: STRING, properties :: MAP) :: (graph :: MAP)
Input parameters
Name | Type | Default |
---|---|---|
kernelTransaction |
STRING |
null |
params |
MAP |
null |
name |
STRING |
null |
properties |
MAP |
null |
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);
CALL apoc.graph.fromCypher(
'MATCH (p:Person)-[r:DIRECTED]->(m:Movie) RETURN *',
{},
'directors',
{description: "Virtual Graph of all directorships"}
)
YIELD graph AS g
RETURN g;
g |
---|
{name: "directors", relationships: [[:DIRECTED], [:DIRECTED]], nodes: [(:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}), (:Person {name: "Lilly Wachowski", born: 1967}), (:Person {name: "Lana Wachowski", born: 1965})], properties: {description: "Virtual Graph of all directorships"}} |