Deleting rows in your table using GraphQL

Delete data in your tables using Astra’s GraphQL API.

As needed, you can delete rows from tables. Use the delete object method to remove the rows in the table you created previously.

Prerequisites

Delete data

After adding the book "Pride and Prejudice" with an insertbook(), you can delete the book using deletebook() to illustrate deleting data. If the call is successful there won’t be a return message.

  • graphQL command

  • Result

mutation deleteOneBook {
  PaP: deletebook(value: {title:"Pride and Prejudice", author: "Jane Austen"}, ifExists: true ) {
    value {
      title
    }
  }
}
{
  "data": {
    "PaP": {
      "value": {
        "title": "Pride and Prejudice"
      }
    }
  }
}

Note the use of ifExists to validate that the book exists before deleting it.

Deletion options

Similar to the option ifExists, you can delete a book using consistency, serialConsistency, or ttl, similar to insertions:

  • graphQL command

  • Result

mutation deleteOneBookCL {
  PaP: deletebook(value: {title:"Pride and Prejudice", author: "Jane Austen"}, ifExists: true, options: {consistency: LOCAL_QUORUM }) {
    value {
      title
    }
  }
}
{
  "data": {
    "PaP": {
      "value": {
        "title": "Pride and Prejudice"
      }
    }
  }
}