Delete
GraphQL allows to query and mutate data. Mutations are operations like create, update and delete. This chapter describes how data can be deleted.
Delete options
The delete operation supports two modes via the options parameter:
| Option | Description |
|---|---|
ARCHIVE | Soft delete - entity is marked as archived and excluded from query results (default) |
ERASE | Hard delete - entity is permanently removed from the database |
By default, entities are archived (ARCHIVE). Archived entities are not returned in normal queries but remain in the database.
Importing an entity again after it was deleted
An archived entity is still stored: its document keeps the rtId and only carries the state Archived, and its
associations are archived with it. This is what happens when the same data is written again:
| Write | Entity with the same rtId is archived | Entity with the same rtId is active |
|---|---|---|
ImportRt without -r (insert only) | The archived entity is replaced by the imported one and is active again. | Fails; the message names the entity and its state Active. |
ImportRt -r (replace / upsert), blueprint apply and update | Replaced, active again. | Replaced. |
After a delete with ERASE | Not applicable, the entity is gone; a plain insert works. | Not applicable. |
Associations of the archived entity are not brought back by themselves; the import creates the associations it names.
A seed entity that an operator deleted comes back with the next replace import or blueprint update, and with an
insert-only import of the same rtId. If an entity must stay deleted, delete it with ERASE and remove it from the seed.
Unique indexes on business keys
A construction kit type can declare an index of type Unique or UniqueNotDeleted on a business key such as a code or
a name:
| Index type | Value of an archived entity |
|---|---|
UniqueNotDeleted | Free: a new entity may use the value. Recommended for business keys. |
Unique | Still blocked, because the archived entity is still stored. Delete the old entity with ERASE, or change the index to UniqueNotDeleted in the construction kit. |
When a Unique index blocks a write, the error message names the entity that was written, the violated index, the
duplicated value and the state of the blocking entity (for example Archived) and says how to resolve it.
Simple delete mutation
To delete entities, use the runtimeEntities endpoint with the delete operation. You need to provide an array of RtEntityId objects, which contain both the rtId and the ckTypeId.
mutation {
runtime {
runtimeEntities {
delete(
options: ARCHIVE
entities: [
{
rtId: "662532d5241639b42933057e"
ckTypeId: "Industry.Energy/EnergyMeter"
}
]
)
}
}
}
The result will be a boolean indicating success:
{
"data": {
"runtime": {
"runtimeEntities": {
"delete": true
}
}
}
}
Permanent delete (ERASE)
To permanently remove entities from the database, use options: ERASE:
mutation {
runtime {
runtimeEntities {
delete(
options: ERASE
entities: [
{
rtId: "662532d5241639b42933057e"
ckTypeId: "Industry.Energy/EnergyMeter"
}
]
)
}
}
}
Using ERASE permanently removes the entity from the database. This operation cannot be undone.
Delete with variables
For programmatic use, it is recommended to use GraphQL variables:
mutation deleteEntities($rtEntityIds: [RtEntityId]!, $options: DeleteOptions) {
runtime {
runtimeEntities {
delete(options: $options, entities: $rtEntityIds)
}
}
}
Variables:
{
"options": "ARCHIVE",
"rtEntityIds": [
{
"rtId": "662532d5241639b42933057e",
"ckTypeId": "Industry.Energy/EnergyMeter"
}
]
}
Batch delete
Multiple entities can be deleted in a single mutation. The entities can be of different types:
mutation deleteEntities($rtEntityIds: [RtEntityId]!) {
runtime {
runtimeEntities {
delete(entities: $rtEntityIds)
}
}
}
Variables:
{
"rtEntityIds": [
{
"rtId": "662532d5241639b42933057e",
"ckTypeId": "Industry.Energy/EnergyMeter"
},
{
"rtId": "65dc6d24cc529cdc46c84fcc",
"ckTypeId": "Industry.Energy/EnergyMeter"
},
{
"rtId": "667acc3be06025c7329fc57c",
"ckTypeId": "Basic/EquipmentGroup"
}
]
}
RtEntityId structure
The RtEntityId input type requires two fields:
| Field | Type | Description |
|---|---|---|
rtId | OctoObjectId | The runtime identifier of the entity |
ckTypeId | String | The construction kit type identifier (e.g., Industry.Energy/EnergyMeter) |
Both fields are required to uniquely identify and delete an entity.
Data permissions
If the tenant protects a Construction Kit type with data policies, deleting an entity needs the Delete grant and visibility: the caller must be able to see the entity (a Read grant on the type, limited to the caller's own entities if the Read grant is). An entity the caller cannot see is answered exactly like an entity that does not exist: the same "not found" error, nothing is deleted, and nothing reveals that the entity exists. A batch is rejected as a whole. See Data permissions for the order of the checks and the effect on roles that can write or delete but not read.
Cascade behavior
When deleting entities, be aware of the cascade behavior:
- Associations: Deleting an entity will remove all associations where this entity is involved
- Child entities: Depending on the association configuration, child entities might be deleted automatically (cascade delete) or the delete might fail if children exist
With ARCHIVE (default), entities can potentially be restored. With ERASE, deletion is permanent and cannot be undone. Always ensure you have proper backups before performing ERASE operations on production data.