Skip to Content
Gqlts

CLI generation

Use the CLI when generation is part of your app setup, CI job, or package script. The command accepts either a local schema file or an introspection endpoint.

Package manager runners

Use whichever runner matches your project:

npx gqlts --schema ./schema.graphql --output ./generated pnpm dlx gqlts --schema ./schema.graphql --output ./generated yarn gqlts --schema ./schema.graphql --output ./generated bunx gqlts --schema ./schema.graphql --output ./generated

When @gqlts/cli is installed in the project, call it from a package script:

{ "scripts": { "generate:gql": "gqlts --schema ./schema.graphql --output ./generated" } }

Generate from an endpoint

gqlts --endpoint https://countries.trevorblades.com --output ./generated

Use --get when the server expects schema introspection over HTTP GET:

gqlts --get --endpoint https://countries.trevorblades.com --output ./generated

Generate from a schema file

gqlts --schema ./schema.graphql --output ./generated

Use this path when your backend already exports SDL in CI or commits a schema snapshot.

Pass headers

Use -H for endpoint introspection that requires auth, tenant, or version headers.

gqlts \ --endpoint https://api.example.com/graphql \ --output ./generated \ -H 'Authorization: Bearer myToken' \ -H 'x-api-version: 2026-05-31'

Map custom scalars

Use -S to map GraphQL scalar names to TypeScript types.

gqlts \ --schema ./schema.graphql \ --output ./generated \ -S DateTime:string \ -S Upload:File \ -S JSON:Record<string,unknown>

If a custom scalar is not mapped, the generated type falls back to any.

Choose module output

By default, Gqlts writes CommonJS output. Use ESM when your app or package is ESM-first:

gqlts --esm --schema ./schema.graphql --output ./generated

Use both outputs when publishing a generated SDK package for mixed consumers:

gqlts --esm-and-cjs --schema ./schema.graphql --output ./generated

Stabilize generated diffs

Use --sort when schema introspection returns fields in an unstable order:

gqlts --sort --endpoint https://api.example.com/graphql --output ./generated

Most servers return stable introspection order. Add this flag only when generated diffs are noisy.

Common flags

FlagPurpose
--schema <path>Read SDL from a local file.
--endpoint <url> / -e <url>Introspect a GraphQL endpoint.
--output <path> / -o <path>Write the generated client directory.
--getUse HTTP GET for endpoint introspection.
-H 'Name: value'Add a request header for endpoint introspection.
-S Scalar:TypeMap a GraphQL scalar to a TypeScript type.
--esmGenerate ESM output only.
--esm-and-cjsGenerate ESM and CommonJS output.
--sortSort generated object properties for stable diffs.