Skip to content
Graffle is a work in progress. Learn more.

Batch

This example shows how to write batches of GraphQL root fields (aka. entrypoints) in the TypeScript interface.

ts
// Our website uses Vitepress+Twoslash. Twoslash does not discover the generated Graffle modules.
// Perhaps we can configure Twoslash to include them. Until we figure that out, we have to
// explicitly import them like this.
import './graffle/modules/global.js'
// ---cut---

import { Graffle } from './graffle/$.js'

const pokemon = Graffle.create()

const pokemons = await pokemon.query.$batch({
  //                                 ^^^^^^
  pokemonByName: {
//^^^^^^^^^^^^^
    $: { name: `Pikachu` },
    name: true,
    id: true,
  },
  trainerByName: {
//^^^^^^^^^^^^^
    $: { name: `Ash` },
    name: true,
    id: true,
  },
})

console.log(pokemons)

Outputs

json
{
  "pokemonByName": [
    {
      "name": "Pikachu",
      "id": "1"
    }
  ],
  "trainerByName": {
    "name": "Ash",
    "id": "1"
  }
}

Released under the MIT License.