population

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 4 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.

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.

func ReferenceFields

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

ReferenceFields returns every relationship and upload field in stable schema order, including fields beneath groups, arrays, and blocks.

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.

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