Week 15: Using Delete versus Destroy Operations on the 8base GraphQL API

Hey there!

When it comes to deleting data, there are two different types of GraphQL operations that can be used: Delete and Destroy. Both of these operations may sound the same, but they work in different ways.

# Delete it!
mutation {
 taskDelete(data: {
  id: "<SOME_RECORD_ID>"
 }) {
  success
 }
}

Delete operations add a “deletedAt” timestamp to records, which means they’re not really deleted, but just stop showing up in query results. This is useful if you need to keep track of what has been deleted, or if you want to be able to undelete (a.k.a. Restore) something later on.

# Destroy it!
mutation {
 taskDestroy(filter: {
  id: "86g20976f0826fd"
 }) {
  success
 }
}

Destroy operations permanently destroy data, which means it can’t be recovered. This is best for cases where you don’t need to keep track of what has been deleted, or when you want to make sure that the data is gone for good.

So which one should you use? It depends on your needs. If you need to track what has been deleted, or if you might want to undelete something later, then you should use a Delete operation. If you’re sure that you never want to see the data again, or if you don’t need to keep track of what’s been deleted, then go ahead and use a Destroy operation.

If you have any questions about this, definitely ask them in the 8base Community (https://community.8base.com)!

Happy deleting!

Sebastian