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 ./generatedWhen @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 ./generatedUse --get when the server expects schema introspection over HTTP GET:
gqlts --get --endpoint https://countries.trevorblades.com --output ./generatedGenerate from a schema file
gqlts --schema ./schema.graphql --output ./generatedUse 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 ./generatedUse both outputs when publishing a generated SDK package for mixed consumers:
gqlts --esm-and-cjs --schema ./schema.graphql --output ./generatedStabilize generated diffs
Use --sort when schema introspection returns fields in an unstable order:
gqlts --sort --endpoint https://api.example.com/graphql --output ./generatedMost servers return stable introspection order. Add this flag only when generated diffs are noisy.
Common flags
| Flag | Purpose |
|---|---|
--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. |
--get | Use HTTP GET for endpoint introspection. |
-H 'Name: value' | Add a request header for endpoint introspection. |
-S Scalar:Type | Map a GraphQL scalar to a TypeScript type. |
--esm | Generate ESM output only. |
--esm-and-cjs | Generate ESM and CommonJS output. |
--sort | Sort generated object properties for stable diffs. |