Documentation
¶
Index ¶
- Variables
- func CurrentID(ctx context.Context) *idproto.ID
- func FormatDescription(paras ...string) string
- func LoadIDs[T Typed](ctx context.Context, srv *Server, ids []ID[T]) ([]T, error)
- type AroundFunc
- type Array
- func MapArrayInput[T Input, R Typed](opt ArrayInput[T], fn func(T) (R, error)) (Array[R], error)
- func NewBoolArray(elems ...bool) Array[Boolean]
- func NewFloatArray(elems ...float64) Array[Float]
- func NewIntArray(elems ...int) Array[Int]
- func NewStringArray(elems ...string) Array[String]
- func ToArray[A any, T Typed](fn func(A) T, elems ...A) Array[T]
- type ArrayInput
- type Boolean
- func (b Boolean) Bool() bool
- func (Boolean) DecodeInput(val any) (Input, error)
- func (Boolean) Decoder() InputDecoder
- func (b Boolean) MarshalJSON() ([]byte, error)
- func (b Boolean) SetField(v reflect.Value) error
- func (b Boolean) ToLiteral() *idproto.Literal
- func (Boolean) Type() *ast.Type
- func (b Boolean) TypeDefinition() *ast.Definition
- func (Boolean) TypeName() string
- func (b *Boolean) UnmarshalJSON(p []byte) error
- type Cache
- type Class
- func (cls Class[T]) Call(ctx context.Context, node Instance[T], fieldName string, args map[string]Input) (Typed, error)
- func (cls Class[T]) Extend(spec FieldSpec, fun FieldFunc)
- func (class Class[T]) Field(name string) (Field[T], bool)
- func (class Class[T]) IDType() (IDType, bool)
- func (class Class[T]) Install(fields ...Field[T])
- func (cls Class[T]) New(id *idproto.ID, val Typed) (Object, error)
- func (cls Class[T]) ParseField(ctx context.Context, astField *ast.Field, vars map[string]any) (Selector, *ast.Type, error)
- func (cls Class[T]) TypeDefinition() *ast.Definition
- func (cls Class[T]) TypeName() string
- func (class Class[T]) Typed() Typed
- type ClassOpts
- type DecoderFunc
- type Definitive
- type Derefable
- type Descriptive
- type DirectiveLocation
- type DirectiveSpec
- type DynamicArrayInput
- func (d DynamicArrayInput) DecodeInput(val any) (Input, error)
- func (d DynamicArrayInput) Decoder() InputDecoder
- func (d DynamicArrayInput) Len() int
- func (d DynamicArrayInput) Nth(i int) (Typed, error)
- func (d DynamicArrayInput) SetField(val reflect.Value) error
- func (d DynamicArrayInput) ToLiteral() *idproto.Literal
- func (d DynamicArrayInput) Type() *ast.Type
- type DynamicArrayOutput
- type DynamicNullable
- type DynamicOptional
- func (n DynamicOptional) DecodeInput(val any) (Input, error)
- func (d DynamicOptional) Decoder() InputDecoder
- func (n DynamicOptional) Deref() (Typed, bool)
- func (i DynamicOptional) MarshalJSON() ([]byte, error)
- func (n DynamicOptional) SetField(val reflect.Value) error
- func (d DynamicOptional) ToLiteral() *idproto.Literal
- func (d DynamicOptional) Type() *ast.Type
- type EnumValue
- type EnumValues
- func (e *EnumValues[T]) DecodeInput(val any) (Input, error)
- func (e *EnumValues[T]) Install(srv *Server)
- func (e *EnumValues[T]) Literal(val T) *idproto.Literal
- func (e *EnumValues[T]) Lookup(val string) (T, error)
- func (e *EnumValues[T]) PossibleValues() ast.EnumValueList
- func (e *EnumValues[T]) Register(val T, desc ...string) T
- func (e *EnumValues[T]) Type() *ast.Type
- func (e *EnumValues[T]) TypeDefinition() *ast.Definition
- func (e *EnumValues[T]) TypeName() string
- type Enumerable
- type ExtendedError
- type Field
- func (field Field[T]) ArgDoc(name string, paras ...string) Field[T]
- func (field Field[T]) ArgSensitive(name string) Field[T]
- func (field Field[T]) Deprecated(paras ...string) Field[T]
- func (field Field[T]) Doc(paras ...string) Field[T]
- func (field Field[T]) DynamicReturnType(ret Typed) Field[T]
- func (field Field[T]) FieldDefinition() *ast.FieldDefinition
- func (field Field[T]) Impure() Field[T]
- func (field Field[T]) Meta() Field[T]
- func (field Field[T]) WithPurity(purity bool) Field[T]
- type FieldFunc
- type FieldSpec
- type Fields
- type Float
- func (Float) DecodeInput(val any) (Input, error)
- func (Float) Decoder() InputDecoder
- func (f Float) Float64() float64
- func (f Float) MarshalJSON() ([]byte, error)
- func (f Float) SetField(v reflect.Value) error
- func (f Float) ToLiteral() *idproto.Literal
- func (Float) Type() *ast.Type
- func (f Float) TypeDefinition() *ast.Definition
- func (Float) TypeName() string
- func (f *Float) UnmarshalJSON(p []byte) error
- type ID
- func (i *ID[T]) Decode(str string) error
- func (i ID[T]) DecodeInput(val any) (Input, error)
- func (i ID[T]) Decoder() InputDecoder
- func (i ID[T]) Display() string
- func (i ID[T]) Encode() (string, error)
- func (i ID[T]) ID() *idproto.ID
- func (i ID[T]) Load(ctx context.Context, server *Server) (Instance[T], error)
- func (i ID[T]) MarshalJSON() ([]byte, error)
- func (i ID[T]) SetField(v reflect.Value) error
- func (i ID[T]) String() string
- func (i ID[T]) ToLiteral() *idproto.Literal
- func (i ID[T]) Type() *ast.Type
- func (i ID[T]) TypeDefinition() *ast.Definition
- func (i ID[T]) TypeName() string
- func (i *ID[T]) UnmarshalJSON(p []byte) error
- type IDType
- type IDable
- type Input
- type InputDecoder
- type InputObject
- type InputObjectSpec
- type InputSpec
- type InputSpecs
- type InputType
- type Inputs
- type Instance
- func (r Instance[T]) ID() *idproto.ID
- func (r Instance[T]) IDFor(ctx context.Context, sel Selector) (*idproto.ID, error)
- func (r Instance[T]) ObjectType() ObjectType
- func (r Instance[T]) Select(ctx context.Context, sel Selector) (val Typed, err error)
- func (r Instance[T]) String() string
- func (o Instance[T]) Type() *ast.Type
- func (r Instance[T]) Unwrap() Typed
- type Int
- func (Int) DecodeInput(val any) (Input, error)
- func (Int) Decoder() InputDecoder
- func (i Int) Int() int
- func (i Int) Int64() int64
- func (i Int) MarshalJSON() ([]byte, error)
- func (i Int) SetField(v reflect.Value) error
- func (i Int) ToLiteral() *idproto.Literal
- func (Int) Type() *ast.Type
- func (i Int) TypeDefinition() *ast.Definition
- func (Int) TypeName() string
- func (i *Int) UnmarshalJSON(p []byte) error
- type Loadable
- type NamedInput
- type Nullable
- type Object
- type ObjectType
- type Optional
- func (n Optional[I]) DecodeInput(val any) (Input, error)
- func (n Optional[I]) Decoder() InputDecoder
- func (n Optional[I]) Deref() (Typed, bool)
- func (n Optional[I]) GetOr(v I) I
- func (i Optional[I]) MarshalJSON() ([]byte, error)
- func (i Optional[I]) ToLiteral() *idproto.Literal
- func (n Optional[I]) ToNullable() Nullable[I]
- func (n Optional[I]) Type() *ast.Type
- func (i *Optional[I]) UnmarshalJSON(p []byte) error
- type ScalarType
- type Selection
- type Selector
- type Server
- func (s *Server) Around(rec AroundFunc)
- func (s *Server) Complexity(typeName, field string, childComplexity int, args map[string]interface{}) (int, bool)
- func (s *Server) Exec(ctx1 context.Context) graphql.ResponseHandler
- func (s *Server) ExecOp(ctx context.Context, gqlOp *graphql.OperationContext) (map[string]any, error)
- func (s *Server) InstallDirective(directive DirectiveSpec)
- func (s *Server) InstallObject(class ObjectType)
- func (s *Server) InstallScalar(scalar ScalarType)
- func (s *Server) InstallTypeDef(def TypeDef)
- func (s *Server) Load(ctx context.Context, id *idproto.ID) (Object, error)
- func (s *Server) ObjectType(name string) (ObjectType, bool)
- func (s *Server) Query(ctx context.Context, query string, vars map[string]any) (map[string]any, error)
- func (s *Server) Resolve(ctx context.Context, self Object, sels ...Selection) (map[string]any, error)
- func (s *Server) Root() Object
- func (s *Server) ScalarType(name string) (ScalarType, bool)
- func (s *Server) Schema() *ast.Schema
- func (s *Server) Select(ctx context.Context, self Object, dest any, sels ...Selector) error
- func (s *Server) TypeDef(name string) (TypeDef, bool)
- type Setter
- type String
- func (String) DecodeInput(val any) (Input, error)
- func (String) Decoder() InputDecoder
- func (s String) MarshalJSON() ([]byte, error)
- func (s String) SetField(v reflect.Value) error
- func (s String) String() string
- func (s String) ToLiteral() *idproto.Literal
- func (String) Type() *ast.Type
- func (s String) TypeDefinition() *ast.Definition
- func (String) TypeName() string
- func (s *String) UnmarshalJSON(p []byte) error
- type Type
- type TypeDef
- type Typed
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
var ( DirectiveLocationQuery = DirectiveLocations.Register("QUERY") DirectiveLocationMutation = DirectiveLocations.Register("MUTATION") DirectiveLocationSubscription = DirectiveLocations.Register("SUBSCRIPTION") DirectiveLocationField = DirectiveLocations.Register("FIELD") DirectiveLocationFragmentDefinition = DirectiveLocations.Register("FRAGMENT_DEFINITION") DirectiveLocationFragmentSpread = DirectiveLocations.Register("FRAGMENT_SPREAD") DirectiveLocationInlineFragment = DirectiveLocations.Register("INLINE_FRAGMENT") DirectiveLocationVariableDefinition = DirectiveLocations.Register("VARIABLE_DEFINITION") DirectiveLocationSchema = DirectiveLocations.Register("SCHEMA") DirectiveLocationScalar = DirectiveLocations.Register("SCALAR") DirectiveLocationObject = DirectiveLocations.Register("OBJECT") DirectiveLocationFieldDefinition = DirectiveLocations.Register("FIELD_DEFINITION") DirectiveLocationArgumentDefinition = DirectiveLocations.Register("ARGUMENT_DEFINITION") DirectiveLocationInterface = DirectiveLocations.Register("INTERFACE") DirectiveLocationUnion = DirectiveLocations.Register("UNION") DirectiveLocationEnum = DirectiveLocations.Register("ENUM") DirectiveLocationEnumValue = DirectiveLocations.Register("ENUM_VALUE") DirectiveLocationInputObject = DirectiveLocations.Register("INPUT_OBJECT") DirectiveLocationInputFieldDefinition = DirectiveLocations.Register("INPUT_FIELD_DEFINITION") )
var DirectiveLocations = NewEnum[DirectiveLocation]()
var ErrCacheMapRecursiveCall = fmt.Errorf("recursive call detected")
Functions ¶
func FormatDescription ¶
Types ¶
type AroundFunc ¶
type Array ¶
type Array[T Typed] []T
Array is an array of GraphQL values.
func MapArrayInput ¶
func NewBoolArray ¶
func NewFloatArray ¶
func NewIntArray ¶
func NewStringArray ¶
type ArrayInput ¶
type ArrayInput[I Input] []I
Array is an array of GraphQL values.
func (ArrayInput[I]) DecodeInput ¶
func (a ArrayInput[I]) DecodeInput(val any) (Input, error)
func (ArrayInput[S]) Decoder ¶
func (a ArrayInput[S]) Decoder() InputDecoder
func (ArrayInput[S]) ToArray ¶
func (a ArrayInput[S]) ToArray() Array[S]
func (ArrayInput[S]) ToLiteral ¶
func (i ArrayInput[S]) ToLiteral() *idproto.Literal
func (ArrayInput[S]) Type ¶
func (a ArrayInput[S]) Type() *ast.Type
type Boolean ¶
type Boolean bool
Boolean is a GraphQL Boolean scalar.
func NewBoolean ¶
func (Boolean) Decoder ¶
func (Boolean) Decoder() InputDecoder
func (Boolean) MarshalJSON ¶
func (Boolean) TypeDefinition ¶
func (b Boolean) TypeDefinition() *ast.Definition
func (*Boolean) UnmarshalJSON ¶
type Cache ¶
type Cache interface { GetOrInitialize( context.Context, digest.Digest, func(context.Context) (Typed, error), ) (Typed, error) }
Cache stores results of pure selections against Server.
type Class ¶
type Class[T Typed] struct { // contains filtered or unexported fields }
Class is a class of Object types.
The class is defined by a set of fields, which are installed into the class dynamically at runtime.
func (Class[T]) Call ¶
func (cls Class[T]) Call(ctx context.Context, node Instance[T], fieldName string, args map[string]Input) (Typed, error)
Call calls a field on the class against an instance.
func (Class[T]) ParseField ¶
func (cls Class[T]) ParseField(ctx context.Context, astField *ast.Field, vars map[string]any) (Selector, *ast.Type, error)
ParseField parses a field selection into a Selector and return type.
func (Class[T]) TypeDefinition ¶
func (cls Class[T]) TypeDefinition() *ast.Definition
Definition returns the schema definition of the class.
The definition is derived from the type name, description, and fields. The type may implement Definitive or Descriptive to provide more information.
Each currently defined field is installed on the returned definition.
type ClassOpts ¶
type ClassOpts[T Typed] struct { // NoIDs disables the default "id" field and disables the IDType method. NoIDs bool // Typed contains the Typed value whose Type() determines the class's type. // // In the simple case, we can just use a zero-value, but it is also allowed // to use a dynamic Typed value. Typed T }
type DecoderFunc ¶
func (DecoderFunc) DecodeInput ¶
func (f DecoderFunc) DecodeInput(val any) (Input, error)
type Definitive ¶
type Definitive interface {
TypeDefinition() *ast.Definition
}
Definitive is a type that knows how to define itself in the schema.
type Derefable ¶
Derefable is a type that wraps another type.
In practice this is only used for Optional and Nullable. It should be used sparingly, since wrapping interfaces explodes very quickly.
type Descriptive ¶
type Descriptive interface {
TypeDescription() string
}
Descriptive is an interface for types that have a description.
The description is used in the schema. To provide a full definition, implement Definitive instead.
type DirectiveLocation ¶
type DirectiveLocation string
func (DirectiveLocation) Decoder ¶
func (DirectiveLocation) Decoder() InputDecoder
func (DirectiveLocation) ToLiteral ¶
func (d DirectiveLocation) ToLiteral() *idproto.Literal
func (DirectiveLocation) Type ¶
func (DirectiveLocation) Type() *ast.Type
type DirectiveSpec ¶
type DirectiveSpec struct { Name string `field:"true"` Description string `field:"true"` Args InputSpecs `field:"true"` Locations []DirectiveLocation `field:"true"` IsRepeatable bool `field:"true"` }
func (DirectiveSpec) DirectiveDefinition ¶
func (d DirectiveSpec) DirectiveDefinition() *ast.DirectiveDefinition
type DynamicArrayInput ¶
func (DynamicArrayInput) DecodeInput ¶
func (d DynamicArrayInput) DecodeInput(val any) (Input, error)
func (DynamicArrayInput) Decoder ¶
func (d DynamicArrayInput) Decoder() InputDecoder
func (DynamicArrayInput) Len ¶
func (d DynamicArrayInput) Len() int
func (DynamicArrayInput) ToLiteral ¶
func (d DynamicArrayInput) ToLiteral() *idproto.Literal
func (DynamicArrayInput) Type ¶
func (d DynamicArrayInput) Type() *ast.Type
type DynamicArrayOutput ¶
func (DynamicArrayOutput) Len ¶
func (d DynamicArrayOutput) Len() int
func (DynamicArrayOutput) MarshalJSON ¶
func (d DynamicArrayOutput) MarshalJSON() ([]byte, error)
func (DynamicArrayOutput) Type ¶
func (d DynamicArrayOutput) Type() *ast.Type
type DynamicNullable ¶
func (DynamicNullable) Deref ¶
func (n DynamicNullable) Deref() (Typed, bool)
func (DynamicNullable) MarshalJSON ¶
func (i DynamicNullable) MarshalJSON() ([]byte, error)
func (DynamicNullable) Type ¶
func (d DynamicNullable) Type() *ast.Type
func (*DynamicNullable) UnmarshalJSON ¶
func (i *DynamicNullable) UnmarshalJSON(p []byte) error
type DynamicOptional ¶
func (DynamicOptional) DecodeInput ¶
func (n DynamicOptional) DecodeInput(val any) (Input, error)
func (DynamicOptional) Decoder ¶
func (d DynamicOptional) Decoder() InputDecoder
func (DynamicOptional) Deref ¶
func (n DynamicOptional) Deref() (Typed, bool)
func (DynamicOptional) MarshalJSON ¶
func (i DynamicOptional) MarshalJSON() ([]byte, error)
func (DynamicOptional) ToLiteral ¶
func (d DynamicOptional) ToLiteral() *idproto.Literal
func (DynamicOptional) Type ¶
func (d DynamicOptional) Type() *ast.Type
type EnumValues ¶
type EnumValues[T EnumValue] struct { // contains filtered or unexported fields }
EnumValues is a list of possible values for an Enum.
func NewEnum ¶
func NewEnum[T EnumValue](vals ...T) *EnumValues[T]
NewEnum creates a new EnumType with the given possible values.
func (*EnumValues[T]) DecodeInput ¶
func (e *EnumValues[T]) DecodeInput(val any) (Input, error)
func (*EnumValues[T]) Install ¶
func (e *EnumValues[T]) Install(srv *Server)
func (*EnumValues[T]) Literal ¶
func (e *EnumValues[T]) Literal(val T) *idproto.Literal
func (*EnumValues[T]) Lookup ¶
func (e *EnumValues[T]) Lookup(val string) (T, error)
func (*EnumValues[T]) PossibleValues ¶
func (e *EnumValues[T]) PossibleValues() ast.EnumValueList
func (*EnumValues[T]) Register ¶
func (e *EnumValues[T]) Register(val T, desc ...string) T
func (*EnumValues[T]) Type ¶
func (e *EnumValues[T]) Type() *ast.Type
func (*EnumValues[T]) TypeDefinition ¶
func (e *EnumValues[T]) TypeDefinition() *ast.Definition
func (*EnumValues[T]) TypeName ¶
func (e *EnumValues[T]) TypeName() string
type Enumerable ¶
type Enumerable interface { // Len returns the number of elements in the Enumerable. Len() int // Nth returns the Nth element of the Enumerable, with 1 representing the // first entry. Nth(int) (Typed, error) }
Enumerable is a value that has a length and allows indexing.
type ExtendedError ¶
ExtendedError is an error that can provide extra data in an error response.
type Field ¶
type Field[T Typed] struct { Spec FieldSpec Func func(context.Context, Instance[T], map[string]Input) (Typed, error) }
Field defines a field of an Object type.
func Func ¶
func Func[T Typed, A any, R any](name string, fn func(ctx context.Context, self T, args A) (R, error)) Field[T]
Func is a helper for defining a field resolver and schema.
The function must accept a context.Context, the receiver, and a struct of arguments. All fields of the arguments struct must be Typed so that the schema may be derived, and Scalar to ensure a default value may be provided.
Arguments use struct tags to further configure the schema:
- `name:"bar"` sets the name of the argument. By default this is the toLowerCamel'd field name.
- `default:"foo"` sets the default value of the argument. The Scalar type determines how this value is parsed.
- `doc:"..."` sets the description of the argument.
The function must return a Typed value, and an error.
To configure a description for the field in the schema, call .Doc on the result.
func NodeFunc ¶
func NodeFunc[T Typed, A any, R any](name string, fn func(ctx context.Context, self Instance[T], args A) (R, error)) Field[T]
NodeFunc is the same as Func, except it passes the Instance instead of the receiver so that you can access its ID.
func (Field[T]) ArgSensitive ¶
func (Field[T]) Deprecated ¶
Impure marks the field as "impure", meaning its result may change over time, or it has side effects.
func (Field[T]) Doc ¶
Doc sets the description of the field. Each argument is joined by two empty lines.
func (Field[T]) DynamicReturnType ¶
Doc sets the description of the field. Each argument is joined by two empty lines.
func (Field[T]) FieldDefinition ¶
func (field Field[T]) FieldDefinition() *ast.FieldDefinition
Definition returns the schema definition of the field.
func (Field[T]) Impure ¶
Impure marks the field as "impure", meaning its result may change over time, or it has side effects.
func (Field[T]) Meta ¶
Impure marks the field as "impure", meaning its result may change over time, or it has side effects.
func (Field[T]) WithPurity ¶
WithPurity sets the purity of the field.
type FieldFunc ¶
FieldFunc is a function that implements a field on an object while limited to the object's external interface.
type FieldSpec ¶
type FieldSpec struct { // Name is the name of the field. Name string // Description is the description of the field. Description string // Args is the list of arguments that the field accepts. Args InputSpecs // Type is the type of the field's result. Type Typed // Meta indicates that the field has no impact on the field's result. Meta bool // Pure indicates that the field is a pure function of its arguments, and // thus can be cached indefinitely. Pure bool // DeprecatedReason deprecates the input and provides a reason. DeprecatedReason string // Module is the module that provides the field's implementation. Module *idproto.ID }
FieldSpec is a specification for a field.
func (FieldSpec) FieldDefinition ¶
func (spec FieldSpec) FieldDefinition() *ast.FieldDefinition
type Float ¶
type Float float64
Float is a GraphQL Float scalar.
func (Float) Decoder ¶
func (Float) Decoder() InputDecoder
func (Float) MarshalJSON ¶
func (Float) TypeDefinition ¶
func (f Float) TypeDefinition() *ast.Definition
func (*Float) UnmarshalJSON ¶
type ID ¶
type ID[T Typed] struct { // contains filtered or unexported fields }
ID is a type-checked ID scalar.
func (ID[T]) DecodeInput ¶
New creates a new ID with the given value.
It accepts either an *idproto.ID or a string. The string is expected to be the base64-encoded representation of an *idproto.ID.
func (ID[T]) Decoder ¶
func (i ID[T]) Decoder() InputDecoder
func (ID[T]) MarshalJSON ¶
func (ID[T]) TypeDefinition ¶
func (i ID[T]) TypeDefinition() *ast.Definition
Definition returns the GraphQL definition of the type.
func (*ID[T]) UnmarshalJSON ¶
type IDType ¶
type IDType interface { Input IDable ScalarType }
type Input ¶
type Input interface { // All Inputs are typed. Typed // All Inputs are able to be represented as a Literal. idproto.Literate // All Inputs now how to decode new instances of themselves. Decoder() InputDecoder }
Input represents any value which may be passed as an input.
type InputDecoder ¶
type InputDecoder interface { // Decode converts a value to the Input type, if possible. DecodeInput(any) (Input, error) }
InputDecoder is a type that knows how to decode values into Inputs.
type InputObject ¶
type InputObject[T Type] struct { Value T }
func (InputObject[T]) Decoder ¶
func (InputObject[T]) Decoder() InputDecoder
func (InputObject[T]) ToLiteral ¶
func (input InputObject[T]) ToLiteral() *idproto.Literal
func (InputObject[T]) Type ¶
func (InputObject[T]) Type() *ast.Type
type InputObjectSpec ¶
type InputObjectSpec struct { Name string Description string Fields InputSpecs }
func MustInputSpec ¶
func MustInputSpec(val Type) InputObjectSpec
func (InputObjectSpec) Install ¶
func (spec InputObjectSpec) Install(srv *Server)
func (InputObjectSpec) Type ¶
func (spec InputObjectSpec) Type() *ast.Type
func (InputObjectSpec) TypeDefinition ¶
func (spec InputObjectSpec) TypeDefinition() *ast.Definition
func (InputObjectSpec) TypeName ¶
func (spec InputObjectSpec) TypeName() string
type InputSpec ¶
type InputSpec struct { // Name is the name of the argument. Name string // Description is the description of the argument. Description string // Type is the type of the argument. Type Input // Default is the default value of the argument. Default Input // DeprecatedReason deprecates the input and provides a reason. DeprecatedReason string // Sensitive indicates that the value of this arg is sensitive and should be // omitted from telemetry. Sensitive bool }
InputSpec specifies a field argument, or an input field.
type InputSpecs ¶
type InputSpecs []InputSpec
func (InputSpecs) ArgumentDefinitions ¶
func (specs InputSpecs) ArgumentDefinitions() []*ast.ArgumentDefinition
func (InputSpecs) FieldDefinitions ¶
func (specs InputSpecs) FieldDefinitions() []*ast.FieldDefinition
type Inputs ¶
type Inputs []NamedInput
type Instance ¶
Instance is an instance of an Object type.
func (Instance[T]) ObjectType ¶
func (r Instance[T]) ObjectType() ObjectType
ID returns the ID of the instance.
type Int ¶
type Int int64
Int is a GraphQL Int scalar.
func NewInt ¶
func NewInt[T constraints.Integer](val T) Int
func (Int) Decoder ¶
func (Int) Decoder() InputDecoder
func (Int) MarshalJSON ¶
func (Int) TypeDefinition ¶
func (i Int) TypeDefinition() *ast.Definition
func (*Int) UnmarshalJSON ¶
type NamedInput ¶
func (NamedInput) String ¶
func (arg NamedInput) String() string
type Nullable ¶
Nullable wraps a type and allows it to be null.
This is used for optional arguments and return values.
func (Nullable[T]) MarshalJSON ¶
func (*Nullable[T]) UnmarshalJSON ¶
type Object ¶
type Object interface { Typed IDable // ObjectType returns the type of the object. ObjectType() ObjectType // IDFor returns the ID representing the return value of the given field. IDFor(context.Context, Selector) (*idproto.ID, error) // Select evaluates the selected field and returns the result. // // The returned value is the raw Typed value returned from the field; it must // be instantiated with a class for further selection. // // Any Nullable values are automatically unwrapped. Select(context.Context, Selector) (Typed, error) }
Object represents an Object in the graph which has an ID and can have sub-selections.
type ObjectType ¶
type ObjectType interface { Type // Typed returns a Typed value whose Type refers to the object type. Typed() Typed // IDType returns the scalar type for the object's IDs. IDType() (IDType, bool) // New creates a new instance of the type. New(*idproto.ID, Typed) (Object, error) // ParseField parses the given field and returns a Selector and an expected // return type. ParseField(context.Context, *ast.Field, map[string]any) (Selector, *ast.Type, error) // Extend registers an additional field onto the type. // // Unlike natively added fields, the extended func is limited to the external // Object interface. Extend(FieldSpec, FieldFunc) }
ObjectType represents a GraphQL Object type.
type Optional ¶
Optional wraps a type and allows it to be null.
This is used for optional arguments and return values.
func (Optional[I]) Decoder ¶
func (n Optional[I]) Decoder() InputDecoder
func (Optional[I]) GetOr ¶
func (n Optional[I]) GetOr(v I) I
GetOr returns the value of the Optional, or the given value if the Optional is empty.
func (Optional[I]) MarshalJSON ¶
func (Optional[I]) ToNullable ¶
func (*Optional[I]) UnmarshalJSON ¶
type ScalarType ¶
type ScalarType interface { Type InputDecoder }
ScalarType represents a GraphQL Scalar type.
type Selector ¶
type Selector struct { Field string Args []NamedInput Nth int }
Selector specifies how to retrieve a value from an Instance.
type Server ¶
type Server struct { // Cache is the inner cache used by the server. It can be replicated to // another *Server to inherit and share caches. // // TODO: copy-on-write Cache Cache // contains filtered or unexported fields }
Server represents a GraphQL server whose schema is dynamically modified at runtime.
func (*Server) Around ¶
func (s *Server) Around(rec AroundFunc)
Around installs a function to be called around every non-cached selection.
func (*Server) Complexity ¶
func (s *Server) Complexity(typeName, field string, childComplexity int, args map[string]interface{}) (int, bool)
Complexity returns the complexity of the given field.
func (*Server) Exec ¶
func (s *Server) Exec(ctx1 context.Context) graphql.ResponseHandler
Exec implements graphql.ExecutableSchema.
func (*Server) InstallDirective ¶
func (s *Server) InstallDirective(directive DirectiveSpec)
InstallDirective installs the given Directive type into the schema.
func (*Server) InstallObject ¶
func (s *Server) InstallObject(class ObjectType)
InstallObject installs the given Object type into the schema.
func (*Server) InstallScalar ¶
func (s *Server) InstallScalar(scalar ScalarType)
InstallScalar installs the given Scalar type into the schema.
func (*Server) InstallTypeDef ¶
InstallTypeDef installs an arbitrary type definition into the schema.
func (*Server) ObjectType ¶
func (s *Server) ObjectType(name string) (ObjectType, bool)
ObjectType returns the ObjectType with the given name, if it exists.
func (*Server) Query ¶
func (s *Server) Query(ctx context.Context, query string, vars map[string]any) (map[string]any, error)
Query is a convenience method for executing a query against the server without having to go through HTTP. This can be useful for introspection, for example.
func (*Server) Resolve ¶
func (s *Server) Resolve(ctx context.Context, self Object, sels ...Selection) (map[string]any, error)
Resolve resolves the given selections on the given object.
Each selection is resolved in parallel, and the results are returned in a map whose keys correspond to the selection's field name or alias.
func (*Server) Root ¶
Root returns the root object of the server. It is suitable for passing to Resolve to resolve a query.
func (*Server) ScalarType ¶
func (s *Server) ScalarType(name string) (ScalarType, bool)
ScalarType returns the ScalarType with the given name, if it exists.
type Setter ¶
Setter allows a type to populate fields of a struct.
This is how builtins are supported.
type String ¶
type String string
String is a GraphQL String scalar.
func (String) Decoder ¶
func (String) Decoder() InputDecoder
func (String) MarshalJSON ¶
func (String) TypeDefinition ¶
func (s String) TypeDefinition() *ast.Definition
func (*String) UnmarshalJSON ¶
type Type ¶
type Type interface { // TypeName returns the name of the type. TypeName() string }
Type is an object that defines a new GraphQL type.
type TypeDef ¶
type TypeDef interface { Type Definitive }
TypeDef is a type whose sole practical purpose is to define a GraphQL type, so it explicitly includes the Definitive interface.