Skip to Content
Codegenheadquery generate

headquery generate

Loads the schema and writes the types. With a config file (written by init), no flags are needed:

npx headquery generate # or: npm run cms:types npx headquery generate --check # CI: exit 1 if the file is out of date

For CI setups see CI.

Without a config file, pass the source and the output:

npx headquery generate --from schema.json --out src/cms.generated.ts npx headquery generate --base-url https://cms.example.com --out src/cms.generated.ts

When the schema can’t be loaded, the CLI prints the underlying error, the most likely cause and a link to the CMS’s troubleshooting page, e.g. Statamic.

Flags

Flags override the config file.

FlagDescription
--fromSchema source: full http(s) URL of the schema endpoint, or a local JSON file
--base-urlCMS origin instead of --from; fetches <base-url><api-prefix><schema-path>
--api-prefixAPI prefix of the CMS (default: /api)
--schema-pathSchema route below the API prefix (default: /headquery/schema)
--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>)
--checkDon’t write; exit 1 if the output file is out of date (for CI)
--configConfig file (default: headquery.config.{ts,mts,mjs,js} in the current directory)

What it generates

One interface per resource (BlogEntry, TagsTerm, SettingsGlobal, …) and a Schema type that the client uses. How the client picks it up is explained under Types. How CMS fields map to TypeScript is listed per CMS, e.g. Statamic field types.

Last updated on