List routes without repeated nodes
The language tabs use earlier client interfaces. Check SDK versions and connection setup before running them.
Find routes between two records without repeating a node inside each route. These are called simple paths.
Before you run it: Dense graphs can contain many routes. Keep both bounds deliberate.
For the quickstart cycle, u1 → u2 → u3 is a route from u1 to u3. Continuing around the cycle would repeat u1, so it is not a simple path. Read the pks list in order; each list is one route, not a set of alternatives.
- Choose u1 and u3Set the source and destination keys.
- Follow links without cyclesDo not revisit a node within the same path.
- Inspect the ordered keysEach returned list describes one bounded route.
Follow the example
- Prepare the self-referencing relationship.
- Set source and destination keys.
- Bound max_depth and max_paths.
- Inspect the returned sequences.
Set up the relationship
First complete the graph quickstart to create graph_demo.people and the u1 → u2 → u3 → u1 cycle. The follows relation is declared in the schema's [[relations]] block. See schemas/reference#relations.
Run the request
curl -G "https://$OC_HOST/v1/tenants/$OC_TENANT/graph/graph_demo.people/all_simple_paths" \
--data-urlencode "rel=follows" \
--data-urlencode "src=u1" \
--data-urlencode "dst=u3" \
--data-urlencode "max_depth=3" \
-H "Authorization: Bearer $OC_TOKEN"Check the result
Each path includes its starting and ending records.
[{"pks": ["u1", "u2", "u3"]}]An array of { pks: [...] } objects, one per discovered path. pks includes both endpoints, in walk order.
Understand the behavior
- Bounded DFS from
src, tracking the path stack to enforce the "no repeated node" rule. - Stops descending past
max_depthand stops emitting pastmax_paths. - The number of simple paths can grow combinatorially with depth - that's why both caps exist.
Important limits and checks
- Not capping
max_depth. The path count is exponential in depth. Even 4-5 hops on a moderately dense graph can hit themax_pathscap immediately. - Using this when you only need one. If you just want the shortest, use dijkstra. If you just want yes/no, use path.