Skip to main content

Getting started

Installation#

  1. Go to the root of your project, and run:
    npm install gqless
    npm install -D @gqless/cli graphql
  2. Next, add a script field to your package.json:
    {
    "scripts": {
    "generate": "gqless generate"
    }
    }
  3. Then run the script once, to create a gqless.config.cjs file:
    npm run generate

Configuring Codegen#

The default config should look something like this:

can also be specified in package.json via gqless key

/**
* @type {import("@gqless/cli").GQlessConfig}
*/
const config = {,
react: true,
scalarTypes: { DateTime: 'string' },
introspection: {
endpoint: 'SPECIFY_ENDPOINT_OR_SCHEMA_FILE_PATH_HERE',
headers: {},
},
destination: './src/gqless/index.ts',
subscriptions: false,
};
module.exports = config;

Point introspection.endpoint to your GraphQL API, adding headers for authorization if necessary. Then run the generate command again, to fetch your schema and output to the destination file:

npm run generate

The output should look like this:

src/gqless
โ”œโ”€โ”€ schema.generated.ts # Will be overwritten when you codegen again
โ””โ”€โ”€ index.ts # GQless client is exported from here, safe to modify options

Getting started#

Configure the fetch() call to your GraphQL server, located inside the queryFetcher() method within src/gqless/index.ts. You might for instance want to dynamically generate the URL depending on environment, or connect it up to your apps authorization.

Usage#

See one of the following for more:

Using with React#

Using the standalone Client#

Last updated on by Sam Denty