Deleting Data

Grafbase automatically generates the delete mutation for models in your schema. Similar to how you update by ID or unique field, we can also delete by ID or unique field.

First, you will want to retrieve an ID for a Comment you wish to delete.

Let's name the operation and define the variables:

mutation DeleteCommentById($id: ID!) {
  commentDelete(by: { id: $id }) {
    deletedId
  }
}

Then using GraphQL variables we'll pass the values along with our request:

{
  "id": "comment_01GFQN16KKPPCGH6PE43VZ7Q1N"
}

Let's finish by deleting a Post by url.

mutation DeletePostById($url: URL!) {
  postDelete(by: { url: $url }) {
    deletedId
  }
}

Just like we did before we can pass the variables along with the request:

{
  "url": "https://grafbase.com"
}
Was this page helpful?