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

Gql Document Node

This example shows how to send a request using a Document instance for the GraphQL document.

ts

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' } } ]
}

Released under the MIT License.