Search code examples
memgraphdb

How one can create a `Map("nodes": List[Node], "edges": List[Relationship])` like the function


I would be glad if someone could answer how one can create a Map("nodes": List[Node], "edges": List[Relationship]) like the function project(p) does, that one can use this as a subgraph in a CALL module.procedure(subgraph, ...) Why do I need this? To chain together outputs from path.subgraph_all and bridges.get. Here is an example of what I mean:

// setup graph for testing
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 0}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 0}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 1}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 3}) CREATE (a)-[:RELATION]->(b);
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 4}) CREATE (a)-[:RELATION]->(b);

// use project(p) - works fine
MATCH p=(:Node)-[:RELATION]-(:Node)
WITH project(p) AS subgraph
CALL bridges.get(subgraph)
YIELD node_from, node_to
RETURN node_from, node_to;

// try to get the subgraph by one node via path.subgraph_all() and then
// try to construct a Map("nodes": List[Node], "edges": List[Relationship])
// to mimic what project() does - does not work
CALL {
MATCH (n:Node)
RETURN n
LIMIT 1
}
CALL path.subgraph_all(n, {})
YIELD nodes, rels
CALL bridges.get({nodes: nodes, edges: rels})
YIELD node_from, node_to
RETURN node_from, node_to;

Solution

  • Unfortunately there's currently no other way to pass the subgraph argument to a procedure other than output of the project() function. The reason for that is because the project() function returns the Graph type object as an output and mapping nodes and edges isn't enough for procedure to recognize the argument as a subgraph.