Genql
Website

Quick Start#

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

To use genql you first need to generate a sdk client

Generate with the cli#

First install the required package from npm

bash
1
npm init -y
2
npm i -D @genql/cli # cli to generate the client code
3
npm i @genql/runtime graphql # runtime dependencies

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

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

bash
1
genql --schema ./schema.graphql --output ./generated
2
# or using a graphql api url
3
genql --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

js
1
// example client generated with genql
2
const { createClient } = require('./generated')
3
4
const client = createClient({
5
url: 'https://countries.trevorblades.com',
6
headers: {
7
'Some-Header': 'hello',
8
},
9
})
10
client
11
.query({
12
countries: {
13
name: true,
14
code: true,
15
},
16
})
17
.then(console.log)

Read more about the graphql client methods in the usage section

Quick Start