I am using Spring Data Neo4j, and trying to execute the following code:
@Query("""
MATCH (orders:Order {id:1})
CALL apoc.path.subgraphAll(orders, {})
YIELD nodes, relationships
RETURN nodes, relationships
""")
List<Order> getOrders(@Param("orderId") Long orderId);
However, it returns only one Order with null fields instead of two with all fields populated.
Before, I was using the following code:
@Query("""
MATCH path = (orders:Order {id: $orderId})-[*]-(commons)
RETURN path
""")
List<Order> getOrders(@Param("orderId") Long orderId);
However, it becomes prolonged after adding 10-20 nodes... So I either need to improve this query or somehow make Spring work with APOC procedures.
I really appreciate it if you could helm me on this matter.
Thank you in advance!
Since your original query returns a path, you can try using apoc.path.expand instead of
apoc.path.subgraphAll:NOTE: The above specifies a lower bound of
0, so a path containing justordwould be returned if that node has no relationships, which I think is maybe what you intended. But this behavior is different than your original query's, which used a (defaulted) lower bound of 1 and would return nothing ifordhas no relationships. If the latter is what you intended, change my0to1.Alternatively, if acceptable, a simple workaround would be to limit the length of the variable-length path search. For example, to limit the search to at most 10 hops, you could replace
[*]with[*..10](or, to use0lower bound:[*0..10]) in your original query. With my query, use10instead of-1.