Graphs { @Description("apoc.graph.fromPaths([paths],'name',{properties}) - creates a virtual graph object for later processing") @Procedure public Stream<VirtualGraph> fromPaths(@Name("paths") List<Path> paths, @Name("name") String name, @Name("properties") Map<String,Object> properties) { List<Node> nodes = new ArrayList<>(1000); List<Relationship> rels = new ArrayList<>(1000); for (Path path : paths) { Iterables.addAll(nodes,path.nodes()); Iterables.addAll(rels,path.relationships()); } return Stream.of(new VirtualGraph(name,nodes,rels,properties)); }  @Description("apoc.graph.fromData([nodes],[relationships],'name',{properties}) | creates a virtual graph object for later processing") @Procedure Stream<VirtualGraph> fromData(@Name("nodes") List<Node> nodes, @Name("relationships") List<Relationship> relationships, @Name("name") String name, @Name("properties") Map<String,Object> properties); @Description("apoc.graph.from(data,'name',{properties}) | creates a virtual graph object for later processing it tries its best to extract the graph information from the data you pass in") @Procedure Stream<VirtualGraph> from(@Name("data") Object data, @Name("name") String name, @Name("properties") Map<String,Object> properties); static boolean extract(Object data, Set<Node> nodes, Set<Relationship> rels); @Description("apoc.graph.fromPaths(path,'name',{properties}) - creates a virtual graph object for later processing") @Procedure Stream<VirtualGraph> fromPath(@Name("path") Path paths, @Name("name") String name, @Name("properties") Map<String,Object> properties); @Description("apoc.graph.fromPaths([paths],'name',{properties}) - creates a virtual graph object for later processing") @Procedure Stream<VirtualGraph> fromPaths(@Name("paths") List<Path> paths, @Name("name") String name, @Name("properties") Map<String,Object> properties); @Description("apoc.graph.fromDB('name',{properties}) - creates a virtual graph object for later processing") @Procedure Stream<VirtualGraph> fromDB(@Name("name") String name, @Name("properties") Map<String,Object> properties); @Description("apoc.graph.fromCypher('kernelTransaction',{params},'name',{properties}) - creates a virtual graph object for later processing") @Procedure Stream<VirtualGraph> fromCypher(@Name("kernelTransaction") String statement,  @Name("params") Map<String,Object> params,@Name("name") String name,  @Name("properties") Map<String,Object> properties); @Description("apoc.graph.fromDocument({json}, {config}) yield graph - transform JSON documents into graph structures") @Procedure(mode = Mode.WRITE) Stream<VirtualGraph> fromDocument(@Name("json") Object document, @Name(value = "config", defaultValue = "{}") Map<String,Object> config); @Description("apoc.graph.validateDocument({json}, {config}) yield row - validates the json, return the result of the validation") @Procedure(mode = Mode.READ) Stream<RowResult> validateDocument(@Name("json") Object document, @Name(value = "config", defaultValue = "{}") Map<String,Object> config); @Context
    public Transaction tx; }
@Test public void testFromPaths() { final Map<String, Object> myGraph = map("name","test","properties",map("answer",42L)); db.executeTransactionally("MATCH (a:Actor {name:'Tom Hanks'}) CREATE (a)-[r:ACTED_IN {roles:'Dott. Henry Goose'}]->(m:Movie {title:'Cloud Atlas'}) RETURN [m] as nodes, [r] as relationships"); db.executeTransactionally("MATCH p = (a:Actor {name:'Tom Hanks'})-[r:ACTED_IN]->(m:Movie) RETURN reduce(output = [], n in collect(nodes(p)) | output + n) AS nodes, reduce(output = [], r in collect(relationships(p)) | output + r) AS relationships", Collections.emptyMap(), result -> { result.stream().flatMap(m -> m.entrySet().stream()) .forEach(e -> myGraph.put(e.getKey(), new ArrayList<>(new HashSet<>((Collection) e.getValue())))); return null; }); TestUtil.testCall(db,"MATCH path = (n)-[r]->(m) WITH collect(path) AS paths CALL apoc.graph.fromPaths(paths,'test',{answer:42}) YIELD graph RETURN *", r -> assertEquals(myGraph, r.get("graph"))); db.executeTransactionally("MATCH (m:Movie {title:'Cloud Atlas'}) DETACH DELETE m"); }