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’sbaseUrl.apiPrefixdefaults to/api(as in the client) andschemaPathto/headquery/schema. Change them if you changed the API route or the schema path on the CMS (for Statamic:statamic.api.routeorheadquery.schema.path).- a full http(s) URL of the schema endpoint.
- a local JSON file, e.g.
"./schema.json".
Other options
| Option | Description |
|---|---|
out | Output .ts file |
token | Bearer token for the schema endpoint (default: $HEADQUERY_SCHEMA_TOKEN) |
target | Adapter target (default: taken from the schema, e.g. statamic) |
module | Module to augment (default: @headquery/<target>) |
How the config is found and applied
- Supported names, in order:
headquery.config.ts,.mts,.mjs,.js. Use--configfor any other path. - Relative
fromandoutpaths resolve against the config file’s directory, so it doesn’t matter where you run the CLI from. - Flags override the config (e.g.
--outfor a one-off run;--fromor--base-urlreplacefrom). The token falls back to$HEADQUERY_SCHEMA_TOKEN. - The config is a regular module, so you can compute values in it.
.envfiles aren’t loaded automatically. The config written byinitloads the env file withprocess.loadEnvFile; real env vars (e.g. CI secrets) win..tsconfigs are loaded by Node’s built-in type stripping (Node ≥ 22.18). On older Node, name the fileheadquery.config.mjsinstead.
Last updated on