Help us shape the future of Go! Take the 2026 Go Developer Survey

hasura

package
v1.4.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 17 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyIfPresent

func ApplyIfPresent(ctx context.Context, cfg *config.Config, projectDir string) error

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

func CompactSchema(raw []byte) string

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

func IsStrict(cfg *config.Config) bool

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

func LegacyErrorText(err error) string

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 SchemaLeafType struct {
	Name *string `json:"name"`
	Kind string  `json:"kind"`
}

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.

func Schema added in v1.4.13

func Schema(ctx context.Context, endpoint, secret string) (SchemaSnapshot, error)

Schema issues only the standard GraphQL introspection query.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL