population

package
v0.22.0 Latest Latest
Warning

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

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

Documentation

Overview

Package population owns schema-driven relationship population traversal.

Population paths are authored field paths, not runtime array indexes. One path therefore applies to every matching row in an array and every matching block instance. Keeping this traversal shared prevents adapters from disagreeing about nested or localized relationship shapes.

Index

Constants

View Source
const (
	// MaxDepth bounds recursive target expansion. It intentionally matches the
	// public REST and GraphQL contract.
	MaxDepth = 5
	// MaxExplicitPaths bounds independently requested population branches. A
	// depth limit alone does not bound a deliberately wide schema or request.
	MaxExplicitPaths = 64
	// MaxExpandedPaths bounds the schema-driven relationship branches visited
	// while recursively populating targets.
	MaxExpandedPaths = 256
)

Variables

This section is empty.

Functions

func DepthPopulations

func DepthPopulations(collection schema.Collection, depth int) []query.Population

DepthPopulations expands every relationship/upload field in a target collection to the remaining depth.

func FieldAtPath

func FieldAtPath(fields []schema.Field, path query.Path) (schema.Field, bool)

FieldAtPath resolves a canonical schema path through groups, arrays, and block discriminators. Repeated runtime rows do not appear in schema paths. It describes the field's configuration: a registered block's field is its shared definition, whose path and ID are definition-relative.

func MapAtPath

func MapAtPath(
	fields []schema.Field,
	values store.Values,
	path query.Path,
	locales LocaleSelection,
	transform func(schema.Field, store.Value) store.Value,
) (mapped store.Values, matched bool)

MapAtPath applies transform to every visible runtime occurrence of the terminal schema field. The returned values are always detached. matched is false when the schema path or runtime shape did not contain an occurrence.

func MapPopulatedDocuments

func MapPopulatedDocuments(
	fields []schema.Field,
	values store.Values,
	allLocales bool,
	transform func(schema.StableID, schema.LocaleCode, store.Document) store.Document,
) store.Values

MapPopulatedDocuments recursively maps already-populated relationship and upload documents in response-shaped values. Single-locale responses have localized fields projected to their scalar/container value; all-locale responses retain locale maps. Callback documents are detached. When a callback runs, the result is a new root map; immutable branches without populated documents are reused. Without populated documents the input root map itself is returned, so callers that need a detached map must copy it.

func MapPopulatedDocumentsAtPaths added in v0.22.0

func MapPopulatedDocumentsAtPaths(
	fields []schema.Field,
	values store.Values,
	allLocales bool,
	transform func(path string, targetID schema.StableID, locale schema.LocaleCode, document store.Document) store.Document,
) store.Values

MapPopulatedDocumentsAtPaths is MapPopulatedDocuments with each document's population path: the authored path of the relationship holding it, as a population request names it. Documents nested in populated documents are left to the transform.

func ReferenceFieldCount added in v0.15.0

func ReferenceFieldCount(fields []schema.Field) int

ReferenceFieldCount is len(ReferenceFields(fields)), counted once per block definition rather than once per placement.

func ReferenceFields

func ReferenceFields(fields []schema.Field) []schema.Field

ReferenceFields returns every relationship and upload field placement in stable schema order, including fields beneath groups, arrays, and blocks. Each field's Path is its canonical placement path; a registered block's field otherwise describes its shared definition. The walk skips field lists without references, so it follows the reference placements rather than every placement of the schema.

func ReferenceTargets added in v0.15.0

func ReferenceTargets(fields []schema.Field) []schema.RelationshipTarget

ReferenceTargets lists the collections that some reference field can target, in first-seen schema order, visiting each block definition once.

func RelationshipDetails

func RelationshipDetails(field schema.Field) *schema.RelationshipField

RelationshipDetails presents uploads through the same finite target shape as relationships.

func VisitAtPath

func VisitAtPath(fields []schema.Field, values store.Values, path query.Path, locales LocaleSelection, visit func(schema.Field, store.Value)) bool

VisitAtPath observes every visible runtime occurrence without changing the caller's values or materializing mutable copies of the traversed containers.

Types

type LocaleSelection

type LocaleSelection struct {
	All   bool
	Chain []schema.LocaleCode
}

LocaleSelection identifies the canonical localized values visible to one store request. All maps every configured locale; otherwise Chain is the requested locale followed by its effective fallbacks.

Jump to

Keyboard shortcuts

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