Skip to main content
Guide
sub() starts an inline traversal that consumes the current stream. Use it for branching operations; use g() only for a top-level traversal entry.

Branching operations

choose and repeat fail after bind with invalid_after_bind_operation.

Retain row-local values

Combine branches with bindings to keep one stable row shape across alternative paths. Bind the starting service, use optional and union sub-traversals to bind each candidate workload path, then project with projectDistinctBindings and coalesce. See Project correlated bindings.

Gate later entries

A batch condition runs an entry only when an earlier entry’s result meets a test. Add the entry with varAsIf / var_as_if instead of varAs. This request returns a user’s posts only when the user exists:
The condition serializes inside the named entry, not as a separate step. Other conditions test for an empty result (varEmpty), a minimum size (varMinSize), or the previous entry (prevNotEmpty). The first entry in a batch cannot depend on a previous result. When the condition is false, the entry does not run: it returns [], even if it ends in count() or exists(), and later entries that read it see no rows. Write batches use the same conditions to create or update a node. Cypher has no batch conditions. In the Cypher tab, the second MATCH runs once for each user the first one finds, so the statement returns no rows when the user does not exist.

Repeat a traversal

repeat runs a sub-traversal on its own output. This request finds users up to three FOLLOWS hops from Alice:
In Go, the configuration builders are helix.Repeat(sub), WithTimes, UntilPred, EmitBefore, EmitAfter, EmitAll, EmitIf, and WithMaxDepth.
  • Stopping. times(n) runs the body n times. until(predicate) stops the whole loop, not single rows, after the first pass in which any row matches; the body always runs at least once. With neither, the loop runs until a pass returns no rows.
  • Depth cap. maxDepth defaults to 100 and stops the loop without an error. With times, the loop runs at most min(times, maxDepth) passes. times(0) and maxDepth(0) fail with invalid_repeat_count.
  • No deduplication. Each pass works on every row the previous pass produced, so cycles revisit nodes and the row count can grow with each hop. Add dedup() after the repeat, and keep the depth small on dense graphs.

Find a shortest path

shortestPath / shortest_path returns the node IDs on one unweighted shortest path. This request finds a path between two users over FOLLOWS edges in either direction:
The response holds the IDs from source to target, such as "path": [12, 40, 7].
  • Rust shortest_path(source, target, max_depth) follows outgoing edges of any label; shortest_path_with adds a label and a direction (Out, In, or Both). The other SDKs take the label and direction as options.
  • The search is breadth-first and visits neighbors in ascending ID order, so ties resolve the same way every time. It returns no edges.
  • The maximum depth is required; 0 fails with invalid_shortest_path_count.
  • Each endpoint must resolve to at most one node; more fails with invalid_query. An endpoint with no node, or no path within the depth, returns [].
  • It starts and ends the traversal, so no step can follow it.

Loop over a parameter

forEachParam / for_each_param runs a batch body once per object in an array parameter, in read and write batches. See Insert many rows.

Bound recursive work

Recursive and fan-out operations must have application-level bounds. Prefer explicit depth, candidate, and response limits. A response limit does not necessarily bound all work performed before that operation: orderBy reads its whole input, and each repeat pass works on the whole previous pass. With an emit mode, rows a pass emits can satisfy a later limit before the next pass starts.

Next steps

Projection and bindings

Emit stable rows from correlated paths.

Parameters

Bind values and bounds at request time.