@tsquid/codegen
v0.3.0
Published
Typed route generator for tsquid: routes.json to TypeScript.
Maintainers
Readme
@tsquid/codegen
Generates typed routes for @tsquid/routes
from routes.json. Ships as WebAssembly. Node ≥ 22.
tsquid-codegen routes.json src/routes/__generated__/routes.ts
tsquid-codegen routes.json src/routes/__generated__/routes.ts --check # exit 1 if staleWrites routes.ts and routes.manifest.json (every route's path, fields, ssr
flag and resolved query, for servers), both or neither. Reads the Relay
persisted-queries file named by persistedQueries, relative to the config.
For each route query, emits <Route>RouteQuery with operation and
getVariables(input) (declared variables, GraphQL defaults, otherwise null).
Each entrypoint also gets an <Entry>EntryPointParams union of { currentRoute, input }.
String fields bound to enum variables need client narrowing before Relay use;
the helper preserves narrowed input types.
import { generate, manifest } from '@tsquid/codegen';
generate(configJson, persistedQueriesJson); // → TypeScript source; throws on an invalid config
manifest(configJson, persistedQueriesJson); // → server manifest JSON; throws on an invalid configpersistedQueriesJson is the file's content, or null when the config names none.
tsquid-relay persist [relay.config.json] [--watch] # reset persistConfig.file, relay-compiler --repersist
tsquid-relay check [relay.config.json] # missing/stale operation idscheck reads only JSON config and .graphql.ts / .graphql.js artifacts under
artifactDirectory or src, honoring source exclusions while including generated
directories. It never reads application TS. persist requires relay-compiler
on PATH and restores the previous persisted file if a one-shot compilation fails.
Route --check remains independent; run both checks in CI.
tsquid-schema fetch [--endpoint URL] [--out schema.graphql]
tsquid-schema check [--endpoint URL | --from server.graphql] [schema.graphql]Introspects the endpoint and writes sorted SDL, or compares normalized remote and
local schemas with a short drift summary. Endpoint defaults to
GRAPHQL_SCHEMA_ENDPOINT, then BASE_URL + /graphql, then
http://localhost:4000/graphql. Introspection failures exit non-zero.
check --from server.graphql compares normalized SDL files without an API.
--from and --endpoint are mutually exclusive. Introspection times out after 30 s.
BASE_URL preserves its path before appending /graphql.
Output is deterministic; commit it. The config and manifest formats are in the
@tsquid/routes README.
