Is there a way to cascade delete all related nodes?

Say that I have a node type, which has a one-to-many relationship with a lot of nodes of another type, which itself has one-to-one relationships with other node types.

Can I make dgraph delete all other nodes of the related node types if I remove a node from the first type? Or rather, simulate the ‘ON DELETE CASCADE’ effect?

Doing it manually seems quite error prone, and could be quite slow due to the need to query all uids before deletion.

There’s no such feature for deletion.

if no nodes should not remains you can do a queue with all nodes related and use * * .

Deletion for JSON

Combine the deletion with a Recursive Query tho.

The S * * deletion only removes the edge towards the other node from what I can tell, it doesn’t remove the node itself, nor any other nodes along the chain. Therefore, I would have to query for all related uids, moving potentially millions of them from dgraph to the backend, just so that I can send them back to dgraph again. This seems quite error prone, and rises in complexity with each layer of related node types.

The “node” will be there, no matters what. It’s just an empty UID. It’s not considered as a node itself. You can ignore them or mark them to use otherwise. In this case you deal with it in the bussines logic.