generate

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package generate provides the schema codegen engine for nself generate.

It fetches the live Hasura GraphQL schema via introspection, parses it into an internal IR (tables, enums, relationships, operations), and renders type-safe client code for TypeScript, Dart, Swift, Kotlin, and Python.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchSchema

func FetchSchema(ctx context.Context, hasuraURL, adminSecret string) (*introspectionSchema, error)

FetchSchema sends an introspection query to the Hasura GraphQL endpoint and returns the raw parsed introspection response.

Types

type GenerateSummary

type GenerateSummary struct {
	Language string
	Files    []string
	Elapsed  time.Duration
}

GenerateSummary reports counts for the diff summary line.

func Render

func Render(ir *IR, opts RenderOptions) ([]GenerateSummary, error)

Render generates all requested language outputs to outDir. It returns one GenerateSummary per language processed.

type IR

type IR struct {
	SchemaName  string
	GeneratedAt string
	Tables      []IRTable
	Enums       []IREnum
	Operations  []IROperation
	Package     string // used by Kotlin renderer
}

IR is the internal representation of the parsed schema. It is language-agnostic and is consumed by per-language renderers.

func BuildIR

func BuildIR(schema *introspectionSchema, schemaName string) *IR

BuildIR converts a raw introspection schema into a language-agnostic IR.

type IRColumn

type IRColumn struct {
	Name     string // camelCase field name
	OrigName string // original snake_case name
	Nullable bool

	// Per-language types
	TSType     string
	DartType   string
	SwiftType  string
	KotlinType string
	PythonType string
}

IRColumn is one field on a table.

type IREnum

type IREnum struct {
	Name   string
	Values []string
}

IREnum is one GraphQL enum type.

type IROperation

type IROperation struct {
	Name         string // PascalCase name
	ConstName    string // camelCase const (TS), variable name (others)
	Kind         string // query | mutation | subscription
	Document     string // raw GraphQL text
	Variables    []IRColumn
	ResultFields []IRColumn
}

IROperation is one .graphql operation (query / mutation / subscription).

type IRTable

type IRTable struct {
	TypeName string // PascalCase type name (e.g. UserProfile)
	OrigName string // original name from Hasura (e.g. user_profile)
	Columns  []IRColumn
}

IRTable represents one database table / GraphQL object type.

type RenderOptions

type RenderOptions struct {
	Langs    []string // subset of: typescript dart swift kotlin python
	OutDir   string
	NoHooks  bool // TypeScript: skip hooks.ts
	Pydantic bool // Python: Pydantic v2 (always true per spec)
}

RenderOptions controls what the renderer produces.

Jump to

Keyboard shortcuts

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