Update mutation

Objects can be updated based on filters on their own fields or those in their nested objects.

Update based on a filter on an object’s fields

Update the name of the author with a given id:

mutation update_author {
  update_author(
    where: {id: {_eq: 3}},
    _set: {name: "Jane"}
  ) {
    affected_rows
  }
}
mutation update_author { update_author( where: {id: {_eq: 3}}, _set: {name: "Jane"} ) { affected_rows } }
{ "data": { "update_author": { "affected_rows": 1 } } }

Update based on a filter on a nested object’s fields

Update the rating of all articles that belong to an author:

mutation update_ratings {
  update_article(
    where: {author: {name: {_eq: "Sidney"}}},
    _set: {rating: 1}
  ) {
    affected_rows
  }
}
mutation update_ratings { update_article( where: {author: {name: {_eq: "Sidney"}}}, _set: {rating: 1} ) { affected_rows } }
{ "data": { "update_article": { "affected_rows": 3 } } }