schema

package
v0.0.0-...-fe7df4e Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHandler

func BuildHandler(db *pgxpool.Pool, schemaName string, ps *ParsedSchema, scalars map[string]scalar.Plugin, modifiers []plugin.QueryModifier, filters []plugin.FilterPlugin, maxDepth int) (http.Handler, error)

BuildHandler creates an HTTP handler that serves GraphQL for the given schema. It builds a dynamic graphql-go schema with Query (list, get) and Mutation (create) per type. Relation fields are resolved by loading the referenced record from the DB.

func CreateTable

func CreateTable(ctx context.Context, db *pgxpool.Pool, schemaName string, t TypeDef, scalars map[string]scalar.Plugin) error

CreateTable creates a PostgreSQL table for the given TypeDef. Table name convention: {schemaName}_{typeName_lowercase}. The "id" field is always TEXT PRIMARY KEY regardless of its SDL scalar. Relation fields produce a FK column: {snake_field_name}_id TEXT [NOT NULL] REFERENCES {schemaName}_{referencedType}(id).

func MaxDepthFromEnv

func MaxDepthFromEnv() int

MaxDepthFromEnv reads the max relation depth from the STRATUM_MAX_DEPTH environment variable.

Types

type FieldDef

type FieldDef struct {
	Name       string
	Type       string // SDL scalar name or referenced type name for relations.
	NonNull    bool
	IsRelation bool // true when Type refers to another object type.
	IsList     bool // true for list relations [OtherType] (1:N).
}

FieldDef represents a single field within an object type.

type ParsedSchema

type ParsedSchema struct {
	Types []TypeDef
}

ParsedSchema is the result of parsing a GraphQL SDL string.

func ParseSDL

func ParseSDL(sdl string) (*ParsedSchema, error)

ParseSDL parses a GraphQL SDL string and extracts user-defined object types. Fields whose type refers to another object type in the same schema are marked as relations (IsRelation = true). The returned types are topologically sorted so that referenced types appear before the types that reference them. Returns an error if the SDL is invalid or defines no object types.

type Schema

type Schema struct {
	Name      string
	SDL       string
	Parsed    *ParsedSchema
	Version   int
	CreatedAt time.Time
	UpdatedAt time.Time
	Handler   http.Handler
}

Schema is a stored, live schema with its metadata and active GraphQL handler.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a thread-safe in-memory registry of live schemas.

func NewStore

func NewStore() *Store

NewStore creates an empty Store.

func (*Store) Get

func (s *Store) Get(name string) (*Schema, bool)

Get retrieves a schema by name. Returns (nil, false) if not found.

func (*Store) Set

func (s *Store) Set(name string, schema *Schema)

Set stores or replaces a schema by name.

type TypeDef

type TypeDef struct {
	Name   string
	Fields []FieldDef
}

TypeDef represents a single GraphQL object type.

type ValidationDetail

type ValidationDetail struct {
	Line    int
	Column  int
	Message string
}

type ValidationError

type ValidationError struct {
	Msg     string
	Details []ValidationDetail
	// contains filtered or unexported fields
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

Jump to

Keyboard shortcuts

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