dehaze

Insert

An insert request only requires the docs argument which is nothing but the array of objects to be inserted.

Insert a single object

Example: Let’s say you have caught a Pikachu! This is how you would add it to your list of caught pokemons:

mutation {
  insert_caught_pokemons(
    docs: [
      {id: "1", name: "Pikachu", combat_power: 500}
    ]
  ) @postgres {
    status
  }
}
const docToBeInserted = {id: "1", name: "Pikachu", combat_power: 500}

const { status } = await db.insert("caught_pokemons")
  .doc(docToBeInserted)
  .apply()

Insert multiple objects of the same type in the same mutation

Example: Add 3 items received from Professor Oak to your list of items:

mutation {
  insert_items(
    docs: [
      {id: "1", type: "Pokeball"},
      {id: "2", type: "Potion"},
      {id: "3", type: "Antidote"}
    ]
  ) @postgres {
    status
  }
}
const docsToBeInserted = [
  {id: "1", type: "Pokeball"},
  {id: "2", type: "Potion"},
  {id: "3", type: "Antidote"}
]

const { status } = await db.insert("items")
  .docs(docsToBeInserted)
  .apply()

Have a technical question?

Improve the docs!