Documentation
¶
Overview ¶
Package ingest is the WRITE side of the catalog: it takes one data source's SDL and turns it into the physical model the catalog storage persists.
What it does, in phase order (Default):
- VALIDATE — the source's declarations are well formed and internally consistent, and its `extend type` blocks are legal;
- PREPARE — the source's own extensions are merged into its definitions, every object type is tagged with @catalog, and the source's prefix is applied to type names and to every reference that names one;
- FINALIZE — @join and @function_call are checked against what they point at, in the source and across the seam through the target provider.
VALIDATE and PREPARE mutate the source's definitions IN PLACE. That is the contract the storage relies on: it walks the source afterwards (store.collect) rather than a separate output. What Compile returns is only what could not go in place — the extensions and the @dependency set.
There is no generation here. The served GraphQL surface — filters, mutation inputs, aggregations, module roots — is built on READ by the catalog storage from the catalog.* tables (pkg/catalog/store/gen_*.go). The GENERATE and ASSEMBLE phases exist in the phase list and have no rules; the pipeline skips an empty phase.
The package was carved out of pkg/catalog/compiler in design-036, when that package's other half — 5 600 lines of generation rules — was deleted. The name says what is left: not a compiler that produces a schema, but the step that admits a source into the catalog.
Index ¶
- func Default() []base.Rule
- func PrefixAndRegister(ctx base.CompilationContext, sourceNames map[string]bool) error
- func RenameDirectiveArgIfSource(d *ast.Directive, argName, prefix string, sourceNames map[string]bool)
- func RenameTypeRefs(t *ast.Type, prefix string, sourceNames map[string]bool)
- type Catalog
- type CatalogTagger
- type DefinitionValidator
- type DependencyCollector
- type ExtensionValidator
- type FunctionCallValidator
- type InternalExtensionMerger
- type JoinValidator
- type Pipeline
- type PrefixPreparer
- type SourceValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Default ¶
Default returns the built-in rules in phase order — the whole pipeline.
What is left after design-036 is the WRITE-side pipeline: validate a source's SDL, merge its own extensions, tag the catalog, apply the prefix, then check the two source-facing declarations that reach beyond a single field — @join and @function_call. The output is the PHYSICAL model the catalog storage persists; the served GraphQL surface is generated on read from `catalog.*`, which is why the GENERATE / ASSEMBLE phases have no rules at all and the pipeline skips them.
func PrefixAndRegister ¶
func PrefixAndRegister(ctx base.CompilationContext, sourceNames map[string]bool) error
PrefixAndRegister applies prefix renaming to source definitions and registers ObjectInfo for data objects. The sourceNames map controls which type references get prefixed — it must include ALL names from the catalog namespace (not just the definitions being processed).
Types ¶
type Catalog ¶
type Catalog interface {
base.DefinitionsSource
CompileOptions() base.Options
}
Catalog is a source of definitions with compile options.
type CatalogTagger ¶
type CatalogTagger struct{}
func (*CatalogTagger) Name ¶
func (r *CatalogTagger) Name() string
func (*CatalogTagger) Phase ¶
func (r *CatalogTagger) Phase() base.Phase
func (*CatalogTagger) ProcessAll ¶
func (r *CatalogTagger) ProcessAll(ctx base.CompilationContext) error
type DefinitionValidator ¶
type DefinitionValidator struct{}
DefinitionValidator validates source schema structure during the VALIDATE phase. It checks that @table/@view types have @pk fields and that field types are valid.
func (*DefinitionValidator) Name ¶
func (r *DefinitionValidator) Name() string
func (*DefinitionValidator) Phase ¶
func (r *DefinitionValidator) Phase() base.Phase
func (*DefinitionValidator) ProcessAll ¶
func (r *DefinitionValidator) ProcessAll(ctx base.CompilationContext) error
type DependencyCollector ¶
type DependencyCollector struct{}
DependencyCollector collects @dependency directives from source definitions AND extensions during the VALIDATE phase and registers them on the compilation context. Only active when opts.IsExtension is true.
This must be a BatchRule (not DefinitionRule) because extension sources primarily contain "extend type" blocks that are extensions, not definitions. DefinitionRules only iterate source.Definitions(), missing extensions entirely.
func (*DependencyCollector) Name ¶
func (r *DependencyCollector) Name() string
func (*DependencyCollector) Phase ¶
func (r *DependencyCollector) Phase() base.Phase
func (*DependencyCollector) ProcessAll ¶
func (r *DependencyCollector) ProcessAll(ctx base.CompilationContext) error
type ExtensionValidator ¶
type ExtensionValidator struct{}
ExtensionValidator validates extension source constraints during the VALIDATE phase. Only active when opts.IsExtension is true. Extension definitions:
- Can only contain views (no @table-only objects)
- Cannot contain modules, functions, system types, or scalars
func (*ExtensionValidator) Name ¶
func (r *ExtensionValidator) Name() string
func (*ExtensionValidator) Phase ¶
func (r *ExtensionValidator) Phase() base.Phase
func (*ExtensionValidator) ProcessAll ¶
func (r *ExtensionValidator) ProcessAll(ctx base.CompilationContext) error
type FunctionCallValidator ¶
type FunctionCallValidator struct{}
FunctionCallValidator validates @function_call and @table_function_call_join directives on fields in data objects. It checks: - Referenced function exists in Function/MutationFunction types - Return type matches the function definition - Field arguments exist in function definition and types match - Args map entries reference valid function arguments - Args map source fields exist in the parent object and types match - All required function arguments are provided
Runs in FINALIZE phase because Function types are created during GENERATE. On the WRITE path there is no GENERATE — see buildFuncRegistry for where the in-flight functions come from instead.
func (*FunctionCallValidator) Name ¶
func (r *FunctionCallValidator) Name() string
func (*FunctionCallValidator) Phase ¶
func (r *FunctionCallValidator) Phase() base.Phase
func (*FunctionCallValidator) ProcessAll ¶
func (r *FunctionCallValidator) ProcessAll(ctx base.CompilationContext) error
type InternalExtensionMerger ¶
type InternalExtensionMerger struct{}
InternalExtensionMerger merges source extensions into source definitions during the PREPARE phase. This handles "extend type Foo { ... }" within the same catalog where Foo is also defined.
Merge rules:
- Stub fields (_stub, _placeholder) from extensions are skipped
- New fields are appended to the definition
- If a field already exists: its type, arguments, position, and default value are replaced; directives are appended; description is updated if non-empty
- Directives, enum values, and interfaces from the extension are appended
When the extension targets a type NOT in the source but present in the provider (target schema), e.g. "extend type Function { ... }", it is promoted to a source-level definition via ctx.PromoteToSource. Promotion once fed the GENERATE rules; today the promoted set is what carries a source's FUNCTIONS through the pipeline — PrefixPreparer renames their return types and FunctionCallValidator reads them as the in-flight half of its registry.
func (*InternalExtensionMerger) Name ¶
func (r *InternalExtensionMerger) Name() string
func (*InternalExtensionMerger) Phase ¶
func (r *InternalExtensionMerger) Phase() base.Phase
func (*InternalExtensionMerger) ProcessAll ¶
func (r *InternalExtensionMerger) ProcessAll(ctx base.CompilationContext) error
type JoinValidator ¶
type JoinValidator struct{}
JoinValidator validates @join directives on fields in data objects. It checks that: - source_fields and references_fields have equal length - Referenced object exists - Source fields exist and are scalars - References fields exist and types match source fields - SQL-referenced fields are valid
Runs in FINALIZE phase. On the WRITE path (the store's partial pipeline) GENERATE and ASSEMBLE register no rules and are skipped, so FINALIZE runs straight after PREPARE — over the prefixed, extension-merged definitions the store is about to persist, which is exactly what this rule needs.
func (*JoinValidator) Name ¶
func (r *JoinValidator) Name() string
func (*JoinValidator) Phase ¶
func (r *JoinValidator) Phase() base.Phase
func (*JoinValidator) ProcessAll ¶
func (r *JoinValidator) ProcessAll(ctx base.CompilationContext) error
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline runs a rule set over one source's SDL, in phase order.
There used to be a package-level Compile() over a mutable global rule registry, filled from init(). With a single rule set left there is nothing to register and nothing to choose: New(Default()...) is the pipeline, and a test that wants a subset passes one explicitly.
func (*Pipeline) Compile ¶
func (c *Pipeline) Compile( ctx context.Context, schema base.Provider, source base.DefinitionsSource, opts base.Options, ) (base.CompiledCatalog, error)
Compile runs the phases over the source's definitions against the target schema. VALIDATE and PREPARE mutate those definitions IN PLACE — prefix, catalog tag, merged extensions — and the returned CompiledCatalog carries what could not go in place: the extensions and the dependency set. GENERATE and ASSEMBLE have no rules and are skipped; the served GraphQL surface is generated on read by the catalog storage.
type PrefixPreparer ¶
type PrefixPreparer struct{}
func (*PrefixPreparer) Name ¶
func (r *PrefixPreparer) Name() string
func (*PrefixPreparer) Phase ¶
func (r *PrefixPreparer) Phase() base.Phase
func (*PrefixPreparer) ProcessAll ¶
func (r *PrefixPreparer) ProcessAll(ctx base.CompilationContext) error
type SourceValidator ¶
type SourceValidator struct{}
SourceValidator rejects redefinition of system types during the VALIDATE phase.
func (*SourceValidator) Match ¶
func (r *SourceValidator) Match(_ *ast.Definition) bool
func (*SourceValidator) Name ¶
func (r *SourceValidator) Name() string
func (*SourceValidator) Phase ¶
func (r *SourceValidator) Phase() base.Phase
func (*SourceValidator) Process ¶
func (r *SourceValidator) Process(_ base.CompilationContext, def *ast.Definition) error