cmd generate - nself-org/cli GitHub Wiki
Generate type-safe client SDK types from the live Hasura schema.
Introspects the running ษณSelf Hasura GraphQL endpoint and emits typed client code for TypeScript, Dart, Swift, Kotlin, and Python. One command keeps all SDK consumers in sync with the database schema. No hand-maintained type files.
nself generate [flags]
| Flag | Default | Description |
|---|---|---|
--lang |
all |
Comma-separated target languages: typescript, dart, swift, kotlin, python, or all
|
--out |
./generated |
Output directory |
--env |
local |
Target environment: local, staging, or prod
|
--watch |
false | Re-run every 30 seconds on schema change |
--operations |
src/**/*.graphql |
Path to .graphql operation files for query/mutation/subscription types |
--no-hooks |
false | Skip React hooks generation (TypeScript only) |
--pydantic |
true | Emit Pydantic v2 models (Python only) |
generated/
โโโ typescript/
โ โโโ schema.ts # DB types (interfaces)
โ โโโ queries.ts # typed query documents and return types
โ โโโ hooks.ts # React hooks wrapping @nself/client
โโโ dart/
โ โโโ models.dart # freezed-compatible data classes
โ โโโ queries.dart # typed query variables and result classes
โโโ swift/
โ โโโ NselfModels.swift # Codable structs
โโโ kotlin/
โ โโโ NselfModels.kt # kotlinx.serialization data classes
โโโ python/
โโโ models.py # Pydantic v2 models
- Fetch live Hasura introspection schema via
HASURA_GRAPHQL_ADMIN_SECRET - Parse schema into an internal IR (tables, enums, relationships)
- Merge
.graphqloperation files into the IR - Render per-language output files to
--outdirectory - Print diff summary: N types, M enums, K operations
The ษณSelf stack must be running before generating against --env local:
nself start
nself generateFor staging or production, set the corresponding env vars:
# Staging
export NSELF_HASURA_STAGING_URL=https://api.myproject.com
export NSELF_HASURA_STAGING_ADMIN_SECRET=<secret>
nself generate --env staging
# Production
export NSELF_HASURA_PROD_URL=https://api.myproject.com
export NSELF_HASURA_PROD_ADMIN_SECRET=<secret>
nself generate --env prod# Generate all languages against the local stack
nself generate
# TypeScript and Dart only
nself generate --lang typescript,dart
# TypeScript against staging, custom output dir
nself generate --env staging --lang typescript --out ./src/generated
# Watch mode: regenerate every 30s when schema changes
nself generate --watch
# Skip React hooks (useful for non-React TypeScript projects)
nself generate --lang typescript --no-hooksFetching schema from http://localhost:8080 ...
Parsed 42 types, 8 enums
[typescript] 3 files written (0.3s)
[dart] 2 files written (0.2s)
[swift] 1 files written (0.1s)
[kotlin] 1 files written (0.1s)
[python] 1 files written (0.1s)
Done in 0.9s. Output: ./generated
Use generated types with the ษณSelf SDK packages:
| Language | Package | Import |
|---|---|---|
| TypeScript | @nself/client |
import type { User } from './generated/typescript/schema' |
| Dart | nself_client |
import 'generated/dart/models.dart' |
| Swift | NselfClient |
import NselfClient; // use NselfModels.swift types |
| Kotlin | io.nself:client |
import io.nself.generated.* |
| Python | nself-client |
from generated.python.models import User |
See SDK reference for full usage.
- The command uses the existing
HASURA_GRAPHQL_ADMIN_SECRETfrom your.envcascade for local environments. - Hasura aggregate, input, and Hasura-internal types are automatically excluded from the output.
-
--watchuses time-based polling (30s interval). It does not use filesystem watchers. - TypeScript output requires
@nself/clientas a peer dependency for hooks. - Dart output generates
freezed-compatible annotations; rundart run build_runner buildto finish code generation.