Usage
create-the-client

Create the client

After generating the client using the cli or the form at gqlts.now.sh (opens in a new tab) you can initialize it passing your options

import { createClient } from './generated_dir'
import { createClient, everything } from './generated_dir'
 
const client = createClient({
    url: 'http://your-api',
    headers: {
        Authorization: 'Bearer xxx',
    },
})
 
await client.query({
    repository: [{ name: 'gqlts', owner: 'remorses' }, { ...everything }],
})

Change headers at runtime

You can pass a function to the headers field to pull the headers at query time, this way you can for example take the auth token from localStorage

import { createClient } from './generated_dir'
 
const client = createClient({
    url: 'http://your-api',
    headers: () => ({
        Authorization: localStorage.get('authToken'),
    }),
})

Using a custom fetcher

You can use your own http fetcher function, must be of type (operation: {query, variables}) => Promise<{data, errors}>

import { createClient } from './generated_dir'
const client = createClient({
    fetcherMethod: (operation) => {
        return fetch('http://your-api', {
            method: 'POST',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(operation),
        }).then((response) => response.json())
    },
})