Switch
Route to one branch by evaluating conditions in order. The conditions live here in cases. Each edge leaving this node carries when: "<case name>": the name of a case, copied exactly, never a condition. An edge with when: "nodes.x.output.branch == 'alert'" names no case and is refused.
- Kind:
switch - Palette: Flow
- Run it on its own: no, only as part of a graph
When to use
Section titled “When to use”- Picking one of several paths from data: a model’s verdict, an HTTP status, an order size.
- Any fork with more than two outcomes, or with a fallback branch.
For “run this step or skip it”, a node’s own if: is shorter than a switch with one case.
Configuration
Section titled “Configuration”| Field | Type | Required | Description |
|---|---|---|---|
cases |
array | yes | Branches tried in order: [{name, when}], when a CEL condition. |
default |
string | no | Branch name when no case matches. |
Output
Section titled “Output”The branch that won.
| Field | Type | Description |
|---|---|---|
branch |
string | Name of the matching case, or the default. |
Example
Section titled “Example”version: hyperspool-graph/v1nodes: - id: route type: switch config: cases: - { name: big, when: "input.amount > 1000" } - { name: flagged, when: "input.flagged == true" } default: normal - id: review type: approval config: { prompt: "Large order, ship it?" } - id: hold type: shell config: { run: ./hold-order.sh } - id: ship type: shell config: { run: ./ship-order.sh }edges: - { from: route, to: review, when: big } - { from: route, to: hold, when: flagged } - { from: route, to: ship, when: normal }Cases are tried in order and the first true one wins, so a large flagged order goes to
review. Each edge’s when is a case name, copied exactly; the condition lives in the case.
A step on a branch the switch didn’t pick is skipped. Without a default, a run where no case
matches fails at the switch. See Branch routing.
See the node reference for every other node.