Documentation
¶
Index ¶
- func GetPrimValueFuncName(primKind proto.RGQLPrimitive_Kind) string
- func ResolveError(rctx *Context, err error)
- func ResolveObject(rctx *Context, table FieldTable)
- func ResolveSlice(ctx *Context, sliceLen int, resolveFunc func(ictx *Context, i int))
- func ResolveValue(rctx *Context, isFinal bool, getValue func() *Value)
- func ResolveValueSlice(ctx *Context, sliceLen int, indexResolver func(i int) *Value)
- type Context
- func (c *Context) ArrayChild(index int) *Context
- func (c *Context) FieldChild(qnode *qtree.QueryTreeNode) *Context
- func (c *Context) GetQueryArgument(argName string) *varstore.VariableReference
- func (c *Context) MarkFinal()
- func (c *Context) Purge()
- func (c *Context) SetError(err error)
- func (c *Context) VirtualChild() *Context
- func (c *Context) WriteValue(val *Value, isFinal bool)
- type FieldResolver
- type FieldTable
- type Observable
- type Value
- type ValueWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 ¶
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, table FieldTable)
ResolveObject watches the query node fields and executes field resolvers.
func ResolveSlice ¶
ResolveSlice resolves a slice of values.
func ResolveValue ¶
ResolveValue resolves a context with a value.
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 ¶
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) VirtualChild ¶
VirtualChild builds a virtual child resolver context that can be canceled if/when a new value becomes available.
func (*Context) WriteValue ¶
WriteValue writes the value at the position.
type FieldResolver ¶
type FieldResolver func(rctx *Context)
FieldResolver resolves a field on an object.
type FieldTable ¶
type FieldTable map[uint32]FieldResolver
FieldTable is a mapping between field ID and resolver.
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) 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 ¶
BuildBoolValue returns a boolean primitive value.
func BuildErrorValue ¶
BuildErrorValue builds a resolver value with an error.
func BuildFloatValue ¶
BuildFloatValue returns a float primitive value.
func BuildIntValue ¶
BuildIntValue returns a int primitive value.
func BuildStringValue ¶
BuildStringValue returns a string primitive value.
type ValueWriter ¶
type ValueWriter interface {
WriteValue(value *Value)
}
ValueWriter handles writing values for fields.