Thanks to visit codestin.com
Credit goes to pkg.go.dev

resolver

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrValueOverflow = errors.New("value overflow")

ErrValueOverflow is returned if a value overflows its type. This is used if an int overflows when converting to int32.

Functions

func GetPrimValueFuncName

func GetPrimValueFuncName(primKind proto.RGQLPrimitive_Kind) string

GetPrimValueFuncName maps the primitive type to a value builder. String -> BuildStringValue Int -> BuildIntValue Bool -> BuildBoolValue, etc... Returns "" if undefined.

func ResolveError

func ResolveError(rctx *Context, err error)

ResolveError applies an error to a resolver context. If err == nil|context.Canceled, calls SetFinal to mark the node as done. Otherwise, marks the resolver context with the error.

func ResolveObject

func ResolveObject(rctx *Context, lookupFieldResolver LookupFieldResolver)

ResolveObject watches the query node fields and executes field resolvers.

func ResolveSlice

func ResolveSlice(ctx *Context, sliceLen int, resolveFunc func(ictx *Context, i int))

ResolveSlice resolves a slice of values.

func ResolveValOverflowError added in v1.4.0

func ResolveValOverflowError(rctx *Context)

ResolveValOverflowError applies a value overflow error.

func ResolveValue

func ResolveValue(rctx *Context, isFinal bool, getValue func() *Value)

ResolveValue resolves a context with a value.

func ResolveValueSlice

func ResolveValueSlice(
	ctx *Context,
	sliceLen int,
	indexResolver func(i int) *Value,
)

ResolveValueSlice iterates over the slice Each function call returns a resolver.Value at index This value is emitted at the array index i.

Types

type Context

type Context struct {
	// Context is the cancellation context
	Context context.Context
	// ContextCancel is the cancellation context cancel func
	ContextCancel context.CancelFunc

	// QNode is the query tree node
	QNode *qtree.QueryTreeNode
	// PathParent is the next parent in the chain that has a path component.
	PathParent *Context
	// PathComponent is the path component.
	// This is sometimes nil (TODO: when?)
	PathComponent *proto.RGQLValue

	// PathMtx locks the path components.
	PathMtx sync.Mutex
	// IsFinal indicates the context is finalized
	IsFinal bool
	// ActiveChildren is the number of active resolver children.
	ActiveChildren int
	// contains filtered or unexported fields
}

Context implements the resolver context. This context tracks: - Current query tree node - Position in output (for result encoding) - If we are an element in an array or not

func NewContext

func NewContext(ctx context.Context, qnode *qtree.QueryTreeNode, writer ValueWriter) *Context

NewContext builds a new root context.

func (*Context) ArrayChild

func (c *Context) ArrayChild(index uint32) *Context

ArrayChild builds a child resolver context with an index in an array.

func (*Context) FieldChild

func (c *Context) FieldChild(qnode *qtree.QueryTreeNode) *Context

FieldChild builds a child resolver context for a field resolver.

func (*Context) GetQueryArgument

func (c *Context) GetQueryArgument(argName string) *varstore.VariableReference

GetQueryArgument returns a query argument by argument name.

func (*Context) MarkFinal

func (c *Context) MarkFinal()

MarkFinal marks the context as complete.

func (*Context) Purge

func (c *Context) Purge()

Purge cancels the context.

func (*Context) SetError

func (c *Context) SetError(err error)

SetError marks an error on the resolver node.

func (*Context) VirtualChild

func (c *Context) VirtualChild() *Context

VirtualChild builds a virtual child resolver context that can be canceled if/when a new value becomes available.

func (*Context) WriteValue

func (c *Context) WriteValue(val *Value, isFinal bool)

WriteValue writes the value at the position.

type FieldResolver

type FieldResolver func(rctx *Context)

FieldResolver resolves a field on an object.

type LookupFieldResolver added in v1.4.0

type LookupFieldResolver func(fieldName string) FieldResolver

LookupFieldResolver looks up the field resolver by field name. Returns nil if not found.

type Observable

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

Observable contains a value that can be subscribed to. The zero value is valid, with an empty val. Untyped nil is considered an empty value.

func NewObservable

func NewObservable(val interface{}) *Observable

NewObservable builds a new observable with an initial value.

func (*Observable) Get

func (o *Observable) Get() interface{}

Get returns the current instantaneous value.

func (*Observable) Set

func (o *Observable) Set(val interface{})

Set sets the next value.

func (*Observable) Subscribe

func (o *Observable) Subscribe(ctx context.Context, write func(v interface{}))

Subscribe subscribes to the value.

type Value

type Value struct {
	Context *Context
	Value   *proto.RGQLPrimitive
	Error   error
}

Value is a primitive value emitted by a resolver.

func BuildBoolValue

func BuildBoolValue(val bool) *Value

BuildBoolValue returns a boolean primitive value.

func BuildErrorValue

func BuildErrorValue(err error) *Value

BuildErrorValue builds a resolver value with an error.

func BuildFloatValue

func BuildFloatValue(val float64) *Value

BuildFloatValue returns a float primitive value.

func BuildIntValue

func BuildIntValue(val int32) *Value

BuildIntValue returns a int primitive value.

func BuildNullValue

func BuildNullValue() *Value

BuildNullValue returns the null primitive value.

func BuildStringValue

func BuildStringValue(val string) *Value

BuildStringValue returns a string primitive value.

type ValueWriter

type ValueWriter interface {
	WriteValue(ctx context.Context, value *Value)
}

ValueWriter handles writing values for fields.

Jump to

Keyboard shortcuts

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