catalog

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCatalogNotFound      = errors.New("catalog not found")
	ErrCatalogAlreadyExists = errors.New("catalog already exists")
)

Functions

func QueryRequestInfo

func QueryRequestInfo(ss ast.SelectionSet) ([]sdl.QueryRequest, sdl.QueryType)

QueryRequestInfo recursively classifies an operation's selection set into typed query requests (meta, data, mutation, function, jq, h3).

Types

type Catalog

type Catalog = sources.Catalog

Aliases — canonical definitions live in pkg/catalog/sources/.

type CatalogManager

type CatalogManager interface {
	// Load/Unload catalogs (for dynamic schema updates)
	AddCatalog(ctx context.Context, name string, catalog Catalog) error
	RemoveCatalog(ctx context.Context, name string) error
	ExistsCatalog(name string) bool
	// ReloadCatalog reloads a catalog. If the source supports incremental
	// changes (IncrementalCatalog), only the delta is compiled and applied.
	// Otherwise falls back to full recompilation.
	ReloadCatalog(ctx context.Context, name string) error
}

type ExtensionCatalog

type ExtensionCatalog = sources.ExtensionCatalog

type IncrementalCatalog

type IncrementalCatalog = sources.IncrementalCatalog

type Manager

type Manager interface {
	// Catalog lifecycle
	AddCatalog(ctx context.Context, name string, catalog Catalog) error
	RemoveCatalog(ctx context.Context, name string) error
	ExistsCatalog(name string) bool
	ReloadCatalog(ctx context.Context, name string) error
	Engine(name string) (engines.Engine, error)
	// RegisterEngine adds an engine for planner routing without compilation.
	// Used by cluster workers where schema is already compiled in CoreDB.
	RegisterEngine(name string, engine engines.Engine)
}

type Operation

type Operation struct {
	// Enriched AST operation definition
	Definition *ast.OperationDefinition

	// All fragments from the document (needed by the planner for FragmentSpread resolution)
	Fragments ast.FragmentDefinitionList

	// Transformed variables
	Variables map[string]any

	// Classified top-level query requests from the selection set
	Queries []sdl.QueryRequest

	// Combined bitmask of all query types in the operation
	QueryType sdl.QueryType
}

Operation is the result of ParseQuery. Contains an enriched AST operation ready for the planner.

func ParseQuery

func ParseQuery(ctx context.Context, p Provider, query string, vars map[string]any, opts ...ParseOption) (*Operation, error)

ParseQuery is a universal pipeline for parsing and validating GraphQL queries.

Pipeline:

  1. VariableTransformer.TransformVariables(ctx, vars) — if set
  2. parser.ParseQuery(query) — gqlparser lexer + parser
  3. validator.Validate(ctx, provider, doc) — our Walker: enrichment + validation + permissions
  4. selectOperation(operations, operationName) — select operation
  5. QueryRequestInfo(op.SelectionSet) — classify queries

Returns: enriched Operation with filled field.Definition, field.ObjectDefinition etc.

type ParseOption

type ParseOption func(*parseConfig)

ParseOption configures ParseQuery.

func WithOperationName

func WithOperationName(name string) ParseOption

WithOperationName sets the operation name to select from the document. Default: "" (single operation).

func WithValidator

func WithValidator(v *validator.Validator) ParseOption

WithValidator sets the validator for ParseQuery. Default: validator.New(rules.DefaultRules()...).

func WithVariableTransformer

func WithVariableTransformer(t VariableTransformer) ParseOption

WithVariableTransformer sets the variable transformer. Default: nil (no transformation).

type Provider

type Provider base.Provider

type Querier

type Querier interface {
	Query(ctx context.Context, query string, vars map[string]any) (*types.Response, error)
}

Querier executes GraphQL queries. Used by VariableTransformer for the jq queryHugr function.

type ReloadableCatalog

type ReloadableCatalog = sources.ReloadableCatalog

type Service

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

Service holds dependencies for query parsing: Provider, Validator, VariableTransformer. Thread-safe (Provider and Validator are immutable after creation).

func NewService

func NewService(p Provider, opts ...ServiceOption) *Service

NewService creates a Service with the given provider and options.

func (*Service) AddCatalog

func (s *Service) AddCatalog(ctx context.Context, name string, catalog Catalog) error

func (*Service) Definitions

func (s *Service) Definitions(ctx context.Context) iter.Seq[*ast.Definition]

func (*Service) Description

func (s *Service) Description(ctx context.Context) string

func (*Service) DirectiveDefinitions

func (s *Service) DirectiveDefinitions(ctx context.Context) iter.Seq2[string, *ast.DirectiveDefinition]

func (*Service) DirectiveForName

func (s *Service) DirectiveForName(ctx context.Context, name string) *ast.DirectiveDefinition

func (*Service) Engine

func (s *Service) Engine(name string) (engines.Engine, error)

func (*Service) ExistsCatalog

func (s *Service) ExistsCatalog(name string) bool

func (*Service) ForName

func (s *Service) ForName(ctx context.Context, name string) *ast.Definition

func (*Service) Implements

func (s *Service) Implements(ctx context.Context, name string) iter.Seq[*ast.Definition]

func (*Service) MutationType

func (s *Service) MutationType(ctx context.Context) *ast.Definition

func (*Service) ParseQuery

func (s *Service) ParseQuery(ctx context.Context, query string, vars map[string]any, operationName string) (*Operation, error)

ParseQuery parses a query using the service's dependencies.

func (*Service) PossibleTypes

func (s *Service) PossibleTypes(ctx context.Context, name string) iter.Seq[*ast.Definition]

func (*Service) Provider

func (s *Service) Provider() Provider

Provider returns the current Provider.

func (*Service) QueryType

func (s *Service) QueryType(ctx context.Context) *ast.Definition

func (*Service) RegisterEngine

func (s *Service) RegisterEngine(name string, engine engines.Engine)

RegisterEngine adds an engine reference for planner routing without going through catalog compilation. Used in read-only mode where schemas are already persisted by the writer node.

func (*Service) ReloadCatalog

func (s *Service) ReloadCatalog(ctx context.Context, name string) error

func (*Service) RemoveCatalog

func (s *Service) RemoveCatalog(ctx context.Context, name string) error

func (*Service) SchemaProvider

func (s *Service) SchemaProvider() Provider

Schema access

func (*Service) SetProvider

func (s *Service) SetProvider(p Provider)

SetProvider replaces the Provider (e.g. on catalog change). NOT thread-safe — call under external lock.

func (*Service) SetVariableTransformer

func (s *Service) SetVariableTransformer(t VariableTransformer)

SetVariableTransformer sets the variable transformer.

func (*Service) SubscriptionType

func (s *Service) SubscriptionType(ctx context.Context) *ast.Definition

func (*Service) Types

func (s *Service) Types(ctx context.Context) iter.Seq2[string, *ast.Definition]

func (*Service) ValidateQuery

func (s *Service) ValidateQuery(ctx context.Context, query string) (*ast.QueryDocument, error)

ValidateQuery parses and validates/enriches a query, returning the full QueryDocument. Unlike ParseQuery it does not select an operation or classify queries. Useful when the caller needs to inspect/filter the enriched AST before execution.

type ServiceOption

type ServiceOption func(*Service)

ServiceOption configures a Service.

func WithServiceValidator

func WithServiceValidator(v *validator.Validator) ServiceOption

WithServiceValidator sets the validator for the service.

func WithServiceVarTransformer

func WithServiceVarTransformer(t VariableTransformer) ServiceOption

WithServiceVarTransformer sets the variable transformer for the service.

type VariableTransformer

type VariableTransformer interface {
	TransformVariables(ctx context.Context, vars map[string]any) (map[string]any, error)
}

VariableTransformer transforms query variables before parsing. The primary implementation is jqVariableTransformer (checks _jq key).

func NewJQVariableTransformer

func NewJQVariableTransformer(querier Querier) VariableTransformer

NewJQVariableTransformer creates a VariableTransformer that processes _jq expressions.

Directories

Path Synopsis
db
schema
Package schema provides serialization utilities for storing GraphQL schema metadata in database tables.
Package schema provides serialization utilities for storing GraphQL schema metadata in database tables.

Jump to

Keyboard shortcuts

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