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

Custom Fetch

This examples shows how to leverage the extension system to override the "exchange" hook's default fetch implementation.

ts
import { 
Graffle
} from 'graffle'
const
graffle
=
Graffle
.
create
({
schema
: `https://countries.trevorblades.com/graphql` })
.
anyware
(({
exchange
}) =>
exchange
({
using
: {
fetch
: async () => {
return new
Response
(
JSON
.
stringify
({
data
: {
countries
: [{
name
: `Canada Mocked!` }] } }))
}, }, }) ) const
data
= await
graffle
.
rawString
({
document
: `{ countries { name } }` })
console
.
log
(
data
)

Outputs

json
{
  "countries": [
    {
      "name": "Canada Mocked!"
    }
  ]
}

Released under the MIT License.