CLI Codegen: Generating Typed GraphQL Schemas
Because GQless derives GraphQL queries from property accesses at runtime, the client needs a lightweight runtime schema map alongside TypeScript interfaces. The CLI inspects your GraphQL server via standard GraphQL Introspection and writes both files in one pass.
1. Running Code Generation
npx gqless generate
# or watch local .graphql SDL files during development
npx gqless generate --watch
2. Generated File Layout
| File | Purpose | Committed to Git? |
|---|---|---|
schema.generated.ts | TypeScript interfaces, enums, input types, and compact runtime field metadata | Yes (recommended for CI) |
index.ts | Pre-wired createClient() instance and custom queryFetcher | Yes (user-editable) |
Custom headers & auth tokens: If your staging GraphQL endpoint requires an API key or bearer header during introspection, define them in
gqless.config.cjs rather than hard-coding secrets in npm scripts.
3. Keeping Bundles Small
The emitted generatedSchema object stores only field type pointers and argument signatures—stripping descriptions and deprecation notes by default. Once generated, pass the schema directly into your core client instance and tune caching behavior via ClientOptions.