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, this can be done in 2 ways:
using the genql website to generate a client npm package for a public graphql api
using the @genql/cli
package to generate code locally
Go to genql.now.sh and compile the form
First install the required package from npm
1npm init -y2npm i -D @genql/cli # cli to generate the client code3npm 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
1genql --schema ./schema.graphql --output ./generated2# or using a graphql api url3genql --endpoint https://countries.trevorblades.com --output ./generated -H 'Authorization: Bearer myToken'
The generated files expose a function createClient
, this creates a client you can use to send requests
Read more about the graphql client methods in the usage section