Gql Document Node
This example shows how to send a request using a Document instance for the GraphQL document.
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'
import { OpenTelemetry } from 'graffle/extensions/opentelemetry'
import { Throws } from 'graffle/extensions/throws'
import { parse } from 'graphql'
const graffle = Graffle
.create()
.transport({
url: `http://localhost:3000/graphql`,
})
.use(Throws)
.use(OpenTelemetry())
const data = await graffle.gql(parse(`
query pokemonByName ($name: String!) {
pokemonByName (name: $name) {
name
trainer {
name
}
}
}
`)).$send({ name: `Pikachu` })
console.log(data)
Outputs
txt
{
pokemonByName: [ { name: 'Pikachu', trainer: { name: 'Ash' } } ]
}