Search by

headquery / statamic

jeslage

Statamic addon for headquery: exports the content model for typed JavaScript clients of the Statamic REST API.

Package info

github.com/jeslage/headquery-statamic

Homepage

Issues

Type:statamic-addon

pkg:composer/headquery/statamic

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

0.2.0 2026-11-13 16:53 UTC

This package is auto-updated.

Last update: 2026-11-13 16:58:47 UTC


README

Early development. headquery is still under development and should not be used in production yet. APIs, generated types and the schema format may change in any 0.x release.

Statamic addon for headquery. It exports your content model so @headquery/codegen can generate TypeScript types for @headquery/statamic, the typed client for Statamic's REST Content API.

Read-only mirror. Issues and pull requests go to the headquery monorepo.

Install

composer require headquery/statamic
php artisan vendor:publish --tag=headquery-config   # optional

The REST API must be enabled in config/statamic/api.php. Only resources enabled there are exported, and only fields in allowed_filters are marked filterable.

Export via CLI (frontend in the same project)

php please headquery:schema --out=../frontend/headquery.schema.json
npx headquery generate --from ../frontend/headquery.schema.json --out ../frontend/src/cms.generated.ts

Export via endpoint (headless, frontend in another repo)

HEADQUERY_SCHEMA_ROUTE=true
HEADQUERY_SCHEMA_TOKEN=a-long-random-token
npx headquery generate \
  --base-url https://cms.example.com \
  --token "$HEADQUERY_SCHEMA_TOKEN" \
  --out src/cms.generated.ts

The endpoint returns 404 unless both variables are set, and 401 without the right bearer token. It sends an ETag, so unchanged schemas answer 304.

Custom fieldtypes

Unknown fieldtypes are exported as unknown. Map them in config/headquery.php (field_types) or dynamically:

use Headquery\Statamic\Schema\FieldMapper;

FieldMapper::extend('seo_pro', fn (array $config) => [
    'type' => 'object',
    'fields' => ['title' => ['type' => 'string'], 'description' => ['type' => 'string']],
]);