Updating rows in your table using GraphQL

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

After creating a table in your keyspace and adding rows, you can update data.

Updates are upserts

Running an update mutation in Astra is an upsert. This means that if the row you are altering doesn’t exist it will be created.

Prerequisites

Using the column that we added earlier, the data for a book is updated with the ISBN value. If the call is successful, a message returns with the newly inserted row data:

  • graphQL command

  • Result

mutation updateOneBook {
  moby: updatebook(value: {title:"Moby Dick", author:"Herman Melville", isbn: "9780140861723"}, ifExists: true ) {
    value {
      title
      author
      isbn
    }
  }
}
{
  "data": {
    "moby": {
      "value": {
        "title": "Moby Dick",
        "author": "Herman Melville",
        "isbn": "9780140861723"
      }
    }
  }
}

It is also possible to update other types of data, such as a set:

  • graphQL command

  • Result

# update one book, adding a SET (genre)
mutation updateOneBookAgain {
 moby: updatebook(value: {title:"Moby Dick", author:"Herman Melville", genre: ["Drama", "Classic lit"]}, ifExists: true ) {
   value {
     title
     author
     genre
   }
 }
}
{
  "data": {
    "moby": {
      "value": {
        "title": "Moby Dick",
        "author": "Herman Melville",
        "genre": [
          "Drama",
          "Classic lit"
        ]
      }
    }
  }
}