Conditional Logic
Edges in Treege support conditional logic based on field values. You can combine multiple conditions to create complex branching flow.
Basic Structure
A conditional edge uses type: "conditional" and carries its conditions inside data:
{
id: "e1",
type: "conditional",
source: "source-node-id",
target: "target-node-id",
data: {
conditions: [
{
field: "field-id",
operator: "===", // "===" | "!==" | ">" | "<" | ">=" | "<="
value: "expected-value",
logicalOperator: "AND" // "AND" | "OR" — combines with the next condition
}
]
}
}Each condition's logicalOperator defines how it combines with the next condition in the array. The last condition's logicalOperator is ignored.
You can also mark an edge as a fallback with data.isFallback: true — it is followed when no other conditional edge from the same source matches.
Supported Operators
| Operator | Description | Example |
|---|---|---|
=== | Equals | age === 18 |
!== | Not equals | status !== "inactive" |
> | Greater than | score > 80 |
< | Less than | price < 100 |
>= | Greater or equal | age >= 21 |
<= | Less or equal | items <= 5 |
Examples
Simple Condition
{
id: "e1",
type: "conditional",
source: "ticket-type",
target: "meal-preference",
data: {
conditions: [
{ field: "ticket-type", operator: "===", value: "vip" }
]
}
}OR Conditions
{
id: "e2",
type: "conditional",
source: "ticket-type",
target: "meal-preference",
data: {
conditions: [
{ field: "ticket-type", operator: "===", value: "vip", logicalOperator: "OR" },
{ field: "ticket-type", operator: "===", value: "regular" }
]
}
}AND Conditions
{
id: "e3",
type: "conditional",
source: "age",
target: "alcohol-preference",
data: {
conditions: [
{ field: "age", operator: ">=", value: "21", logicalOperator: "AND" },
{ field: "country", operator: "===", value: "US" }
]
}
}Note: Condition value is compared as a string. Operators like > / < coerce both sides to numbers when comparing numeric fields.