apoc.graph.fromData
Procedure APOC Core
apoc.graph.fromData([nodes],[relationships],'name',{properties}) | creates a virtual graph object for later processing
Signature
apoc.graph.fromData(nodes :: LIST? OF NODE?, relationships :: LIST? OF RELATIONSHIP?, name :: STRING?, properties :: MAP?) :: (graph :: MAP?)
Input parameters
Name | Type | Default |
---|---|---|
nodes |
LIST? OF NODE? |
null |
relationships |
LIST? OF RELATIONSHIP? |
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);
MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)
WITH collect(m) + collect(p) AS nodes, collect(r) AS relationships
CALL apoc.graph.fromData(nodes, relationships, "movies", {})
YIELD graph AS g
UNWIND keys(g) AS key
RETURN key, g[key] AS value;
key | value |
---|---|
"name" |
"movies" |
"relationships" |
[[:ACTED_IN {roles: ["Neo"]}], [:ACTED_IN {roles: ["Trinity"]}], [:ACTED_IN {roles: ["Morpheus"]}], [:ACTED_IN {roles: ["Agent Smith"]}]] |
"nodes" |
[(:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}), (:Person {name: "Keanu Reeves", born: 1964}), (:Person {name: "Carrie-Anne Moss", born: 1967}), (:Person {name: "Laurence Fishburne", born: 1961}), (:Person {name: "Hugo Weaving", born: 1960})] |
"properties" |
{} |