-
Notifications
You must be signed in to change notification settings - Fork 0
Example 4 Route with BranchPipe
Fernando Koch edited this page Mar 30, 2026
·
3 revisions
Understand how GraphK routes one request to one matching branch.
A request reaches your system, but not every request should follow the same path. You need one route to win and execute.
import graphk
branch = graphk.BranchPipe(
nodes=[
(graphk.Matcher(task="route-a"), graphk.SequencePipe(nodes=[graphk.demo.RouteNode("A")])),
(graphk.Matcher(task="route-b"), graphk.SequencePipe(nodes=[graphk.demo.RouteNode("B")])),
(graphk.Matcher(task="route-c"), graphk.SequencePipe(nodes=[graphk.demo.RouteNode("C")])),
],
)
program = graphk.Program(
{"route": graphk.SequencePipe(nodes=[branch])}
)
emitter = graphk.Emitter(program)
emitter.request("route", graphk.Session(task="route-b"))
print(emitter.response())- the emitter selects the
routepipeline from the program - all branch tests are checked
- the matching branch is selected
- only one branch executes
This is GraphK’s main exclusive-routing pattern.