apoc.graph.fromPath

Procedure

apoc.graph.fromPath(path Path, name String, props String) - generates a virtual sub-graph by extracting all of the nodes and relationships from the data returned by the given path.

Signature

apoc.graph.fromPath(path :: PATH?, name :: STRING?, properties :: MAP?) :: (graph :: MAP?)

Input parameters

Name Type Default

path

PATH?

null

name

STRING?

null

properties

MAP?

null

Output parameters

Name Type

graph

MAP?

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 path = (:Person)-[:ACTED_IN]->(:Movie)
CALL apoc.graph.fromPath(path,'test', {})
YIELD graph AS g
RETURN g.nodes AS nodes, g.relationships AS relationships;
Table 1. Results
nodes relationships

[(:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}), (:Person {name: "Hugo Weaving", born: 1960})]

[[:ACTED_IN {roles: ["Agent Smith"]}]]

[(:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}), (:Person {name: "Laurence Fishburne", born: 1961})]

[[:ACTED_IN {roles: ["Morpheus"]}]]

[(:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}), (:Person {name: "Carrie-Anne Moss", born: 1967})]

[[:ACTED_IN {roles: ["Trinity"]}]]

[(:Movie {tagline: "Welcome to the Real World", title: "The Matrix", released: 1999}), (:Person {name: "Keanu Reeves", born: 1964})]

[[:ACTED_IN {roles: ["Neo"]}]]