API -- Relationship Editing
Relations are edited through nested mutation inputs.
Relation Actions
Each related item uses the _action field:
ADD→ creates a relation and optional target rowEDIT→ edits an existing related rowREMOVE→ removes the relation onlyDELETE→ removes both relation and target row
Semantics
- Relation mutations participate in the parent mutation transaction
- All relation actions are validated by write rules
Examples
Assume:
personhas a 1:n relationaddresses- Target table is
address
ADD — Create New Related Row and Link It
Creates a new address row and links it to the person.
mutation {
edit_person(id: 123, input: {
addresses: [
{
_action: ADD
street: "Main Street 1"
city: "Stockholm"
}
]
}) {
id
}
}
Result:
- New
addressrow is created - Relation between
personandaddressis created
ADD — Link Existing Related Row
Links an existing address row without creating a new one.
Result:
- No new row is created
- Only the relation edge is created
EDIT — Edit Existing Related Row
Edits the related address row through the relation.
mutation {
edit_person(id: 123, input: {
addresses: [
{
_action: EDIT
id: 987
city: "Gothenburg"
}
]
})
}
Result:
- The address row is updated
- The relation remains unchanged
REMOVE — Remove Relation Only
Removes the relation but keeps the related row.
Result:
- The relation is removed
- The address row still exists
DELETE — Remove Relation and Target Row
Removes both the relation and the related row.
Result:
- The relation is removed
- The address row is deleted