Skip to Content
CodegenConfig file

Config file

Instead of passing flags every time, add a headquery.config.ts next to your package.json (headquery init writes one for you). The CLI finds it automatically, so the command becomes just npx headquery generate.

import { } from "@headquery/codegen"; export default ({ : { : "https://cms.example.com" }, // → https://cms.example.com/api/headquery/schema : "src/cms.generated.ts", : .., });

from

One of:

  • { baseUrl, apiPrefix?, schemaPath? }: the CMS origin, like the client’s baseUrl. apiPrefix defaults to /api (as in the client) and schemaPath to /headquery/schema. Change them if you changed the API route or the schema path on the CMS (for Statamic: statamic.api.route or headquery.schema.path).
  • a full http(s) URL of the schema endpoint.
  • a local JSON file, e.g. "./schema.json".

Other options

OptionDescription
outOutput .ts file
tokenBearer token for the schema endpoint (default: $HEADQUERY_SCHEMA_TOKEN)
targetAdapter target (default: taken from the schema, e.g. statamic)
moduleModule to augment (default: @headquery/<target>)

How the config is found and applied

  • Supported names, in order: headquery.config.ts, .mts, .mjs, .js. Use --config for any other path.
  • Relative from and out paths resolve against the config file’s directory, so it doesn’t matter where you run the CLI from.
  • Flags override the config (e.g. --out for a one-off run; --from or --base-url replace from). The token falls back to $HEADQUERY_SCHEMA_TOKEN.
  • The config is a regular module, so you can compute values in it.
  • .env files aren’t loaded automatically. The config written by init loads the env file with process.loadEnvFile; real env vars (e.g. CI secrets) win.
  • .ts configs are loaded by Node’s built-in type stripping (Node ≥ 22.18). On older Node, name the file headquery.config.mjs instead.
Last updated on