Quick Start

Quick Start

Gqlts translate typed code into graphql queries, enabling you to get auto completion and validation for your graphql queries.

To use gqlts you first need to generate a sdk client

Generate with the cli

First install the required package from npm

npm init -y
npm i -D @gqlts/cli # cli to generate the client code
npm i @gqlts/runtime graphql # runtime dependencies

@gqlts/cli is a dev dependency because it is only required to generate the client, @gqlts/runtime instead is a direct dependency of the generated code

Then run the gqlts command to generate the client inside a directory

gqlts --schema ./schema.graphql --output ./generated
# or using a graphql api url
gqlts --endpoint https://countries.trevorblades.com --output ./generated -H 'Authorization: Bearer myToken'

Using the client

The generated files expose a function createClient, this creates a client you can use to send requests

// example client generated with gqlts
const { createClient } = require('./generated')
 
const client = createClient({
    url: 'https://countries.trevorblades.com',
    headers: {
        'Some-Header': 'hello',
    },
})
client
    .query({
        countries: {
            name: true,
            code: true,
        },
    })
    .then(console.log)

Read more about the graphql client methods in the usage section