dehaze

Transactions

You can perform multiple mutations in a single database transaction with automatic rollbacks in case of failures. (i.e. either all of the mutations in a transaction will succeed or none of them)

For example, let’s say you want to trade a pokemon, i.e. add a new pokemon to your list of pokemons and delete one from it simultaneously. This is how you would do it:

mutation {
  insert_caught_pokemons(
    docs: [
      {id: 5, name: "Charizard"}
    ]
  ) @postgres {
    status
  }
  delete_caught_pokemons(
    where: {id: 4}
  ) @postgres {
    status
  }
}
const batch = db.beginBatch()

batch.add(db.insert("caught_pokemons").docs({id: 5, name: "Charizard"}))
batch.add(db.delete("caught_pokemons").where(cond("id", "==", 4)))

const { status } = batch.apply()

Have a technical question?

Improve the docs!