The latest on deep (cascading?) mutations/deletions via GraphQL

Looking for efficient GraphQL mutation format to delete something along the lines of: Author (id 123) and all of that author’s Posts (and potentially other nested item types within Posts, such as Media…).

I see year old posts on here which seem to come to the conclusion that it’s not possible via a single, cascading GraphQL mutation. So questions:

  1. Has this changed since a year ago?

  2. What is the best non-DQL, GraphQL-only way to go about this on Dgraph Cloud?

A) Is it to delete each type separately and specify each and every node id? Author {id: 123} and Posts [{id: 234}, {id: 567}…] and Media[{id:789},{id:0123]…?

B) Is it to delete each type separately: Delete Media filtered where associated Posts = [{id: 234}, {id: 567}…] and Delete Posts filtered where associated Author = {id: 123} and Delete Author {id: 123}…?

Ah yes, looks like Dgraph still does not allow deep filtering so it seems B is not possible.

C) Or is there now a deep/cascading method for mutations?

Thanks.

1 Like

Currently there is no way to do this in Dgraph except manually. This includes dql and graphql.

I have proposed a Reference Directive which mimics SQL’s

  • ON DELETE CASCADE
  • ON UPDATE CASCADE

However, Dgraph has not shown any interest in adding this basic foreign key feature in the future.

For the moment, you can only emulate this with a delete and update Lambda Webhook. This is basically an After (add/delete/update) Trigger Function.

J

1 Like

OK, thank you Jonathan.