'Remove user while also removing unused tags in many-to-many relationship in GraphQL?

I'm using Hasura for this.

Say for example I have a users, tags and users_tags table in a many-to-many relationship.

User's can define multiple tags (like a persons hobbies) and each tag can belong to multiple people.

Table users {
  id int [pk increment]
}

Table tags {
  id int [pk increment]
  name text
}

Table users_tags {
  id int [pk increment]
  user [ref: - user.id]
  tag [ref: - tags.id]
}

The users_tags table is a many-to-many table.

When a new user is created, I can create new tags and associate them with users just fine.

But when a user is deleted, what GraphQL mutation can I use to remove tags from both tags and users_tags if they don't point to other users.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source