# (Cascade)-Delete Directive

**URL:** <https://discuss.dgraph.io/t/cascade-delete-directive/11342>\
**Category:** GraphQL\
**Tags:** kind:question, kind:enhancement, kind:feature\
**Created:** [November 7, 2020, 11:23am UTC](https://discuss.dgraph.io/t/cascade-delete-directive/11342 "2020-11-07T11:23:26Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![maaft](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maaft](https://discuss.dgraph.io/u/maaft)\
**Post date:** [November 7, 2020, 11:23am UTC](https://discuss.dgraph.io/t/cascade-delete-directive/11342/1 "2020-11-07T11:23:26Z")

</div>

I know that this question has come up multiple times now but I want to express the importance of such a feature. Also this thread could be used to track this feature as I think that the other threads rather present workarounds to this currently missing functionality.

Suggested Schema:

```auto
directive @delete(soft: Boolean, cascade: Boolean, fields: [String]) on OBJECT | INTERFACE
directive @showDeleted on OBJECT | INTERFACE

type Foo @delete(cascade: true, fields: ["bars"]) {
  bars: [Bar!]
  foobars: [FooBar!]
  a: String!
}

type Bar @delete(soft: true) @showDeleted {
  b: String!
  lols: [Lol!]
}

type FooBar {
   c: String!
}

```

This schema would generate the following functionality:

- calling `deleteFoo` will **hard-delete** the node itself and all child fields listed using the @cascade directive
- `Bar` makes use of the soft-delete flag. On deletion a timestamp `deletedAt` would be set.
- `queryBar` and `getBar` would default to only retrieve non-deleted nodes but you could opt-in to show also deleted nodes (by providing @showDeleted directive like here)
- The field `lols` on `type Bar` will not get deleted on calling `deleteFoo` because the `cascade` flag is not set inside its @delete directive.
- `FooBar` is a regular type. Existing behaviour applies.

What do you guys think?

@amaster507 @pawan @rajas

---

_[View the full topic](https://discuss.dgraph.io/t/cascade-delete-directive/11342)._
