Documentation
¶
Overview ¶
Package hasura provides the single step-function entry point that wires Hasura metadata application into the nself lifecycle (start/deploy), so that `<project>/hasura/metadata/` on disk is never silently ignored.
Purpose: FIX-CLI-3 (P6 2026-09-04) — `nself build/start/deploy` never ran `hasura metadata apply`, so staging tracked 9 tables and prod 21 while the repo declared ~51 (46 np_/nself_/shopify_/idme_ tables never applied to either environment). This package closes that gap with one idempotent call. Inputs: a context, *config.Config, and the project directory. Outputs: an error only when metadata is present, apply fails, AND strict mode is on; otherwise a printed warning (dev default) or silent skip. Constraints: kept in its own package/file with a single call site in cmd/commands/start.go and the deploy paths, so it rebases cleanly against concurrent start*.go/internal/compose work tonight (coordination note, P6 crunch 2026-09-04).
Index ¶
- func ApplyIfPresent(ctx context.Context, cfg *config.Config, projectDir string) error
- func CompactSchema(raw []byte) string
- func Endpoint() string
- func IsStrict(cfg *config.Config) bool
- func LegacyErrorText(err error) string
- type PermissionSnapshot
- type SchemaField
- type SchemaLeafType
- type SchemaNamedType
- type SchemaRoot
- type SchemaSnapshot
- type SchemaType
- type TablePermissions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyIfPresent ¶
ApplyIfPresent applies `<projectDir>/hasura/metadata/` to the running Hasura instance if that directory exists; otherwise it is a clean no-op.
Idempotent: safe to call on every start/deploy — Hasura's replace_metadata API is itself idempotent (CLI-R already relies on this for `nself db hasura metadata apply`).
Strictness: controlled by NSELF_HASURA_METADATA_STRICT (explicit override, "true"/"false"), else defaults to strict in staging/prod and warn-only in dev (cfg.Env). In warn mode a failed apply or inconsistency report prints but never fails the caller; in strict mode both fail it.
func CompactSchema ¶ added in v1.4.13
CompactSchema returns the legacy text representation byte for byte.
func Endpoint ¶ added in v1.4.13
func Endpoint() string
Endpoint preserves the legacy MCP endpoint precedence.
func IsStrict ¶
IsStrict reports whether metadata-apply failures should fail the caller, per NSELF_HASURA_METADATA_STRICT (explicit override) else cfg.Env (staging/prod = strict, dev = warn-only). Exported for reuse by the deploy paths, which need the same decision before deciding whether to fail a remote rolling restart.
func LegacyErrorText ¶ added in v1.4.13
LegacyErrorText preserves the pre-command MCP error text with secret redaction.
Types ¶
type PermissionSnapshot ¶ added in v1.4.13
type PermissionSnapshot struct {
Tables []TablePermissions `json:"tables"`
Raw []byte `json:"-"`
Valid bool `json:"-"`
}
PermissionSnapshot is a metadata-only table permission list.
func Permissions ¶ added in v1.4.13
func Permissions(ctx context.Context, endpoint, secret string) (PermissionSnapshot, error)
Permissions exports Hasura metadata and selects table permission objects only.
type SchemaField ¶ added in v1.4.13
type SchemaField struct {
Name string `json:"name"`
Type SchemaNamedType `json:"type"`
}
type SchemaLeafType ¶ added in v1.4.13
type SchemaNamedType ¶ added in v1.4.13
type SchemaNamedType struct {
Name *string `json:"name"`
Kind string `json:"kind"`
OfType *SchemaLeafType `json:"ofType,omitempty"`
}
type SchemaRoot ¶ added in v1.4.13
type SchemaRoot struct {
Name string `json:"name"`
}
type SchemaSnapshot ¶ added in v1.4.13
type SchemaSnapshot struct {
Types []SchemaType `json:"types"`
QueryType *SchemaRoot `json:"query_type,omitempty"`
MutationType *SchemaRoot `json:"mutation_type,omitempty"`
SubscriptionType *SchemaRoot `json:"subscription_type,omitempty"`
Raw []byte `json:"-"`
Valid bool `json:"-"`
}
SchemaSnapshot is the command's typed data. Raw retains the exact legacy response.
type SchemaType ¶ added in v1.4.13
type SchemaType struct {
Name string `json:"name"`
Kind string `json:"kind"`
Fields []SchemaField `json:"fields,omitempty"`
}
SchemaType describes a GraphQL type without reading any rows.
type TablePermissions ¶ added in v1.4.13
type TablePermissions struct {
Table string `json:"table"`
Permissions map[string]interface{} `json:"permissions"`
}
TablePermissions preserves the legacy MCP structured result shape.