...

Package graphql

import "github.com/99designs/gqlgen/graphql"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Constants
Variables
func AddError(ctx context.Context, err error)
func AddErrorf(ctx context.Context, format string, args ...interface{})
func BuildUnmarshalerMap(unmarshaler ...interface{}) map[reflect.Type]reflect.Value
func CoerceList(v interface{}) []interface{}
func CollectAllFields(ctx context.Context) []string
func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error
func DefaultRecover(ctx context.Context, err interface{}) error
func ErrorOnPath(ctx context.Context, err error) error
func GetErrors(ctx context.Context) gqlerror.List
func GetExtension(ctx context.Context, name string) interface{}
func GetExtensions(ctx context.Context) map[string]interface{}
func GetFieldErrors(ctx context.Context, rctx *FieldContext) gqlerror.List
func GetPath(ctx context.Context) ast.Path
func GetStartTime(ctx context.Context) time.Time
func HasFieldError(ctx context.Context, rctx *FieldContext) bool
func HasOperationContext(ctx context.Context) bool
func Recover(ctx context.Context, err interface{}) (userMessage error)
func RegisterExtension(ctx context.Context, key string, value interface{})
func StartOperationTrace(ctx context.Context) context.Context
func UnmarshalAny(v interface{}) (interface{}, error)
func UnmarshalBoolean(v interface{}) (bool, error)
func UnmarshalDuration(v interface{}) (time.Duration, error)
func UnmarshalFloat(v interface{}) (float64, error)
func UnmarshalFloatContext(ctx context.Context, v interface{}) (float64, error)
func UnmarshalID(v interface{}) (string, error)
func UnmarshalInputFromContext(ctx context.Context, raw, v interface{}) error
func UnmarshalInt(v interface{}) (int, error)
func UnmarshalInt32(v interface{}) (int32, error)
func UnmarshalInt64(v interface{}) (int64, error)
func UnmarshalIntID(v interface{}) (int, error)
func UnmarshalMap(v interface{}) (map[string]interface{}, error)
func UnmarshalString(v interface{}) (string, error)
func UnmarshalTime(v interface{}) (time.Time, error)
func UnmarshalUUID(v any) (uuid.UUID, error)
func UnmarshalUint(v interface{}) (uint, error)
func UnmarshalUint32(v interface{}) (uint32, error)
func UnmarshalUint64(v interface{}) (uint64, error)
func WithFieldContext(ctx context.Context, rc *FieldContext) context.Context
func WithFreshResponseContext(ctx context.Context) context.Context
func WithOperationContext(ctx context.Context, rc *OperationContext) context.Context
func WithPathContext(ctx context.Context, fic *PathContext) context.Context
func WithResponseContext(ctx context.Context, presenterFunc ErrorPresenterFunc, recoverFunc RecoverFunc) context.Context
func WithRootFieldContext(ctx context.Context, rc *RootFieldContext) context.Context
func WithUnmarshalerMap(ctx context.Context, maps map[reflect.Type]reflect.Value) context.Context
type Array
    func (a Array) MarshalGQL(writer io.Writer)
type Cache
type CollectedField
    func CollectFields(reqCtx *OperationContext, selSet ast.SelectionSet, satisfies []string) []CollectedField
    func CollectFieldsCtx(ctx context.Context, satisfies []string) []CollectedField
type ContextMarshaler
    func MarshalFloatContext(f float64) ContextMarshaler
type ContextUnmarshaler
type ContextWriterFunc
    func (f ContextWriterFunc) MarshalGQLContext(ctx context.Context, w io.Writer) error
type Deferrable
type DeferredGroup
type DeferredResult
type ErrorPresenterFunc
type ExecutableSchema
type ExecutableSchemaMock
    func (mock *ExecutableSchemaMock) Complexity(typeName string, fieldName string, childComplexity int, args map[string]interface{}) (int, bool)
    func (mock *ExecutableSchemaMock) ComplexityCalls() []struct {TypeName string FieldName string ChildComplexity int Args map[string]interface{}}
    func (mock *ExecutableSchemaMock) Exec(ctx context.Context) ResponseHandler
    func (mock *ExecutableSchemaMock) ExecCalls() []struct {Ctx context.Context}
    func (mock *ExecutableSchemaMock) Schema() *ast.Schema
    func (mock *ExecutableSchemaMock) SchemaCalls() []struct {}
type FieldContext
    func GetFieldContext(ctx context.Context) *FieldContext
    func (r *FieldContext) Path() ast.Path
type FieldInterceptor
type FieldMiddleware
type FieldSet
    func NewFieldSet(fields []CollectedField) *FieldSet
    func (m *FieldSet) AddField(field CollectedField)
    func (m *FieldSet) Concurrently(i int, f func(context.Context) Marshaler)
    func (m *FieldSet) Dispatch(ctx context.Context)
    func (m *FieldSet) MarshalGQL(writer io.Writer)
type FieldStats
type GraphExecutor
type HandlerExtension
type MapCache
    func (m MapCache) Add(_ context.Context, key string, value interface{})
    func (m MapCache) Get(_ context.Context, key string) (value interface{}, ok bool)
type Marshaler
    func MarshalAny(v interface{}) Marshaler
    func MarshalBoolean(b bool) Marshaler
    func MarshalDuration(d time.Duration) Marshaler
    func MarshalFloat(f float64) Marshaler
    func MarshalID(s string) Marshaler
    func MarshalInt(i int) Marshaler
    func MarshalInt32(i int32) Marshaler
    func MarshalInt64(i int64) Marshaler
    func MarshalIntID(i int) Marshaler
    func MarshalMap(val map[string]interface{}) Marshaler
    func MarshalString(s string) Marshaler
    func MarshalTime(t time.Time) Marshaler
    func MarshalUUID(id uuid.UUID) Marshaler
    func MarshalUint(i uint) Marshaler
    func MarshalUint32(i uint32) Marshaler
    func MarshalUint64(i uint64) Marshaler
    func MarshalUpload(f Upload) Marshaler
    func WrapContextMarshaler(ctx context.Context, m ContextMarshaler) Marshaler
type Mutation
type NoCache
    func (n NoCache) Add(_ context.Context, _ string, _ interface{})
    func (n NoCache) Get(_ context.Context, _ string) (value interface{}, ok bool)
type Omittable
    func OmittableOf[T any](value T) Omittable[T]
    func (o Omittable[T]) IsSet() bool
    func (o Omittable[T]) MarshalJSON() ([]byte, error)
    func (o *Omittable[T]) UnmarshalJSON(bytes []byte) error
    func (o Omittable[T]) Value() T
    func (o Omittable[T]) ValueOK() (T, bool)
type OperationContext
    func GetOperationContext(ctx context.Context) *OperationContext
    func (c *OperationContext) Error(ctx context.Context, err error)
    func (c *OperationContext) Errorf(ctx context.Context, format string, args ...interface{})
    func (c *OperationContext) Recover(ctx context.Context, err interface{}) error
    func (c *OperationContext) Validate(ctx context.Context) error
type OperationContextMutator
type OperationHandler
type OperationInterceptor
type OperationMiddleware
type OperationParameterMutator
type PathContext
    func GetPathContext(ctx context.Context) *PathContext
    func NewPathWithField(field string) *PathContext
    func NewPathWithIndex(index int) *PathContext
    func (fic *PathContext) Path() ast.Path
type Query
type RawParams
    func (p *RawParams) AddUpload(upload Upload, key, path string) *gqlerror.Error
type RecoverFunc
type RequestContext
    func GetRequestContext(ctx context.Context) *RequestContext
type Resolver
type ResolverContext
    func GetResolverContext(ctx context.Context) *ResolverContext
type Response
    func ErrorResponse(ctx context.Context, messagef string, args ...interface{}) *Response
type ResponseHandler
    func OneShot(resp *Response) ResponseHandler
type ResponseInterceptor
type ResponseMiddleware
type RootFieldContext
    func GetRootFieldContext(ctx context.Context) *RootFieldContext
type RootFieldInterceptor
type RootFieldMiddleware
type RootResolver
type Stats
    func (c *Stats) GetExtension(name string) interface{}
    func (c *Stats) SetExtension(name string, data interface{})
type Status
type Subscription
type TraceTiming
type Transport
type Unmarshaler
type Upload
    func UnmarshalUpload(v interface{}) (Upload, error)
type WriterFunc
    func (f WriterFunc) MarshalGQL(w io.Writer)

Package files

any.go bool.go cache.go coercion.go context_field.go context_operation.go context_path.go context_response.go context_root_field.go deferred.go duration.go error.go executable_schema.go executable_schema_mock.go fieldset.go float.go handler.go id.go input.go int.go jsonw.go map.go omittable.go oneshot.go recovery.go response.go root.go stats.go string.go time.go uint.go upload.go uuid.go version.go

Constants

const Version = "v0.17.45"

Variables

var (
    Null  = &lit{nullLit}
    True  = &lit{trueLit}
    False = &lit{falseLit}
)

Now is time.Now, except in tests. Then it can be whatever you want it to be.

var Now = time.Now

func AddError

func AddError(ctx context.Context, err error)

AddError sends an error to the client, first passing it through the error presenter.

func AddErrorf

func AddErrorf(ctx context.Context, format string, args ...interface{})

AddErrorf writes a formatted error to the client, first passing it through the error presenter.

func BuildUnmarshalerMap

func BuildUnmarshalerMap(unmarshaler ...interface{}) map[reflect.Type]reflect.Value

BuildUnmarshalerMap returns a map of unmarshal functions of the ExecutableContext to use with the WithUnmarshalerMap function.

func CoerceList

func CoerceList(v interface{}) []interface{}

CoerceList applies coercion from a single value to a list.

func CollectAllFields

func CollectAllFields(ctx context.Context) []string

CollectAllFields returns a slice of all GraphQL field names that were selected for the current resolver context. The slice will contain the unique set of all field names requested regardless of fragment type conditions.

func DefaultErrorPresenter

func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error

func DefaultRecover

func DefaultRecover(ctx context.Context, err interface{}) error

func ErrorOnPath

func ErrorOnPath(ctx context.Context, err error) error

func GetErrors

func GetErrors(ctx context.Context) gqlerror.List

func GetExtension

func GetExtension(ctx context.Context, name string) interface{}

func GetExtensions

func GetExtensions(ctx context.Context) map[string]interface{}

GetExtensions returns any extensions registered in the current result context

func GetFieldErrors

func GetFieldErrors(ctx context.Context, rctx *FieldContext) gqlerror.List

GetFieldErrors returns a list of errors that occurred in the given field

func GetPath

func GetPath(ctx context.Context) ast.Path

func GetStartTime

func GetStartTime(ctx context.Context) time.Time

GetStartTime should only be called by the handler package, it will be set into request context as Stats.Start

func HasFieldError

func HasFieldError(ctx context.Context, rctx *FieldContext) bool

HasFieldError returns true if the given field has already errored

func HasOperationContext

func HasOperationContext(ctx context.Context) bool

HasOperationContext checks if the given context is part of an ongoing operation

Some errors can happen outside of an operation, eg json unmarshal errors.

func Recover

func Recover(ctx context.Context, err interface{}) (userMessage error)

func RegisterExtension

func RegisterExtension(ctx context.Context, key string, value interface{})

RegisterExtension allows you to add a new extension into the graphql response

func StartOperationTrace

func StartOperationTrace(ctx context.Context) context.Context

StartOperationTrace captures the current time and stores it in context. This will eventually be added to request context but we want to grab it as soon as possible. For transports that can only handle a single graphql query per http requests you don't need to call this at all, the server will do it for you. For transports that handle multiple (eg batching, subscriptions) this should be called before decoding each request.

func UnmarshalAny

func UnmarshalAny(v interface{}) (interface{}, error)

func UnmarshalBoolean

func UnmarshalBoolean(v interface{}) (bool, error)

func UnmarshalDuration

func UnmarshalDuration(v interface{}) (time.Duration, error)

UnmarshalDuration returns the duration from a string in ISO8601 format

func UnmarshalFloat

func UnmarshalFloat(v interface{}) (float64, error)

func UnmarshalFloatContext

func UnmarshalFloatContext(ctx context.Context, v interface{}) (float64, error)

func UnmarshalID

func UnmarshalID(v interface{}) (string, error)

func UnmarshalInputFromContext

func UnmarshalInputFromContext(ctx context.Context, raw, v interface{}) error

UnmarshalInputFromContext allows unmarshaling input object from a context.

func UnmarshalInt

func UnmarshalInt(v interface{}) (int, error)

func UnmarshalInt32

func UnmarshalInt32(v interface{}) (int32, error)

func UnmarshalInt64

func UnmarshalInt64(v interface{}) (int64, error)

func UnmarshalIntID

func UnmarshalIntID(v interface{}) (int, error)

func UnmarshalMap

func UnmarshalMap(v interface{}) (map[string]interface{}, error)

func UnmarshalString

func UnmarshalString(v interface{}) (string, error)

func UnmarshalTime

func UnmarshalTime(v interface{}) (time.Time, error)

func UnmarshalUUID

func UnmarshalUUID(v any) (uuid.UUID, error)

func UnmarshalUint

func UnmarshalUint(v interface{}) (uint, error)

func UnmarshalUint32

func UnmarshalUint32(v interface{}) (uint32, error)

func UnmarshalUint64

func UnmarshalUint64(v interface{}) (uint64, error)

func WithFieldContext

func WithFieldContext(ctx context.Context, rc *FieldContext) context.Context

func WithFreshResponseContext

func WithFreshResponseContext(ctx context.Context) context.Context

func WithOperationContext

func WithOperationContext(ctx context.Context, rc *OperationContext) context.Context

func WithPathContext

func WithPathContext(ctx context.Context, fic *PathContext) context.Context

func WithResponseContext

func WithResponseContext(ctx context.Context, presenterFunc ErrorPresenterFunc, recoverFunc RecoverFunc) context.Context

func WithRootFieldContext

func WithRootFieldContext(ctx context.Context, rc *RootFieldContext) context.Context

func WithUnmarshalerMap

func WithUnmarshalerMap(ctx context.Context, maps map[reflect.Type]reflect.Value) context.Context

WithUnmarshalerMap returns a new context with a map from input types to their unmarshaler functions.

type Array

type Array []Marshaler

func (Array) MarshalGQL

func (a Array) MarshalGQL(writer io.Writer)

type Cache

Cache is a shared store for APQ and query AST caching

type Cache interface {
    // Get looks up a key's value from the cache.
    Get(ctx context.Context, key string) (value interface{}, ok bool)

    // Add adds a value to the cache.
    Add(ctx context.Context, key string, value interface{})
}

type CollectedField

type CollectedField struct {
    *ast.Field

    Selections ast.SelectionSet
    Deferrable *Deferrable
}

func CollectFields

func CollectFields(reqCtx *OperationContext, selSet ast.SelectionSet, satisfies []string) []CollectedField

CollectFields returns the set of fields from an ast.SelectionSet where all collected fields satisfy at least one of the GraphQL types passed through satisfies. Providing an empty or nil slice for satisfies will return collect all fields regardless of fragment type conditions.

func CollectFieldsCtx

func CollectFieldsCtx(ctx context.Context, satisfies []string) []CollectedField

This is just a convenient wrapper method for CollectFields

type ContextMarshaler

type ContextMarshaler interface {
    MarshalGQLContext(ctx context.Context, w io.Writer) error
}

func MarshalFloatContext

func MarshalFloatContext(f float64) ContextMarshaler

type ContextUnmarshaler

type ContextUnmarshaler interface {
    UnmarshalGQLContext(ctx context.Context, v interface{}) error
}

type ContextWriterFunc

type ContextWriterFunc func(ctx context.Context, writer io.Writer) error

func (ContextWriterFunc) MarshalGQLContext

func (f ContextWriterFunc) MarshalGQLContext(ctx context.Context, w io.Writer) error

type Deferrable

type Deferrable struct {
    Label string
}

type DeferredGroup

type DeferredGroup struct {
    Path     ast.Path
    Label    string
    FieldSet *FieldSet
    Context  context.Context
}

type DeferredResult

type DeferredResult struct {
    Path   ast.Path
    Label  string
    Result Marshaler
    Errors gqlerror.List
}

type ErrorPresenterFunc

type ErrorPresenterFunc func(ctx context.Context, err error) *gqlerror.Error

type ExecutableSchema

type ExecutableSchema interface {
    Schema() *ast.Schema

    Complexity(typeName, fieldName string, childComplexity int, args map[string]interface{}) (int, bool)
    Exec(ctx context.Context) ResponseHandler
}

type ExecutableSchemaMock

ExecutableSchemaMock is a mock implementation of ExecutableSchema.

func TestSomethingThatUsesExecutableSchema(t *testing.T) {

	// make and configure a mocked ExecutableSchema
	mockedExecutableSchema := &ExecutableSchemaMock{
		ComplexityFunc: func(typeName string, fieldName string, childComplexity int, args map[string]interface{}) (int, bool) {
			panic("mock out the Complexity method")
		},
		ExecFunc: func(ctx context.Context) ResponseHandler {
			panic("mock out the Exec method")
		},
		SchemaFunc: func() *ast.Schema {
			panic("mock out the Schema method")
		},
	}

	// use mockedExecutableSchema in code that requires ExecutableSchema
	// and then make assertions.

}
type ExecutableSchemaMock struct {
    // ComplexityFunc mocks the Complexity method.
    ComplexityFunc func(typeName string, fieldName string, childComplexity int, args map[string]interface{}) (int, bool)

    // ExecFunc mocks the Exec method.
    ExecFunc func(ctx context.Context) ResponseHandler

    // SchemaFunc mocks the Schema method.
    SchemaFunc func() *ast.Schema
    // contains filtered or unexported fields
}

func (*ExecutableSchemaMock) Complexity

func (mock *ExecutableSchemaMock) Complexity(typeName string, fieldName string, childComplexity int, args map[string]interface{}) (int, bool)

Complexity calls ComplexityFunc.

func (*ExecutableSchemaMock) ComplexityCalls

func (mock *ExecutableSchemaMock) ComplexityCalls() []struct {
    TypeName        string
    FieldName       string
    ChildComplexity int
    Args            map[string]interface{}
}

ComplexityCalls gets all the calls that were made to Complexity. Check the length with:

len(mockedExecutableSchema.ComplexityCalls())

func (*ExecutableSchemaMock) Exec

func (mock *ExecutableSchemaMock) Exec(ctx context.Context) ResponseHandler

Exec calls ExecFunc.

func (*ExecutableSchemaMock) ExecCalls

func (mock *ExecutableSchemaMock) ExecCalls() []struct {
    Ctx context.Context
}

ExecCalls gets all the calls that were made to Exec. Check the length with:

len(mockedExecutableSchema.ExecCalls())

func (*ExecutableSchemaMock) Schema

func (mock *ExecutableSchemaMock) Schema() *ast.Schema

Schema calls SchemaFunc.

func (*ExecutableSchemaMock) SchemaCalls

func (mock *ExecutableSchemaMock) SchemaCalls() []struct {
}

SchemaCalls gets all the calls that were made to Schema. Check the length with:

len(mockedExecutableSchema.SchemaCalls())

type FieldContext

type FieldContext struct {
    Parent *FieldContext
    // The name of the type this field belongs to
    Object string
    // These are the args after processing, they can be mutated in middleware to change what the resolver will get.
    Args map[string]interface{}
    // The raw field
    Field CollectedField
    // The index of array in path.
    Index *int
    // The result object of resolver
    Result interface{}
    // IsMethod indicates if the resolver is a method
    IsMethod bool
    // IsResolver indicates if the field has a user-specified resolver
    IsResolver bool
    // Child allows getting a child FieldContext by its field collection description.
    // Note that, the returned child FieldContext represents the context as it was
    // before the execution of the field resolver. For example:
    //
    //	srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (interface{}, error) {
    //		fc := graphql.GetFieldContext(ctx)
    //		op := graphql.GetOperationContext(ctx)
    //		collected := graphql.CollectFields(opCtx, fc.Field.Selections, []string{"User"})
    //
    //		child, err := fc.Child(ctx, collected[0])
    //		if err != nil {
    //			return nil, err
    //		}
    //		fmt.Println("child context %q with args: %v", child.Field.Name, child.Args)
    //
    //		return next(ctx)
    //	})
    //
    Child func(context.Context, CollectedField) (*FieldContext, error)
}

func GetFieldContext

func GetFieldContext(ctx context.Context) *FieldContext

func (*FieldContext) Path

func (r *FieldContext) Path() ast.Path

type FieldInterceptor

FieldInterceptor called around each field

type FieldInterceptor interface {
    InterceptField(ctx context.Context, next Resolver) (res interface{}, err error)
}

type FieldMiddleware

type FieldMiddleware func(ctx context.Context, next Resolver) (res interface{}, err error)

type FieldSet

type FieldSet struct {
    Values   []Marshaler
    Invalids uint32
    // contains filtered or unexported fields
}

func NewFieldSet

func NewFieldSet(fields []CollectedField) *FieldSet

func (*FieldSet) AddField

func (m *FieldSet) AddField(field CollectedField)

func (*FieldSet) Concurrently

func (m *FieldSet) Concurrently(i int, f func(context.Context) Marshaler)

func (*FieldSet) Dispatch

func (m *FieldSet) Dispatch(ctx context.Context)

func (*FieldSet) MarshalGQL

func (m *FieldSet) MarshalGQL(writer io.Writer)

type FieldStats

type FieldStats struct {
    // When field execution started
    Started time.Time

    // When argument marshaling finished
    ArgumentsCompleted time.Time

    // When the field completed running all middleware. Not available inside field middleware!
    Completed time.Time
}

type GraphExecutor

type GraphExecutor interface {
    CreateOperationContext(ctx context.Context, params *RawParams) (*OperationContext, gqlerror.List)
    DispatchOperation(ctx context.Context, rc *OperationContext) (ResponseHandler, context.Context)
    DispatchError(ctx context.Context, list gqlerror.List) *Response
}

type HandlerExtension

HandlerExtension adds functionality to the http handler. See the list of possible hook points below Its important to understand the lifecycle of a graphql request and the terminology we use in gqlgen before working with these

+--- REQUEST   POST /graphql --------------------------------------------+
| +- OPERATION query OpName { viewer { name } } -----------------------+ |
| |  RESPONSE  { "data": { "viewer": { "name": "bob" } } }             | |
| +- OPERATION subscription OpName2 { chat { message } } --------------+ |
| |  RESPONSE  { "data": { "chat": { "message": "hello" } } }          | |
| |  RESPONSE  { "data": { "chat": { "message": "byee" } } }           | |
| +--------------------------------------------------------------------+ |
+------------------------------------------------------------------------+
type HandlerExtension interface {
    // ExtensionName should be a CamelCase string version of the extension which may be shown in stats and logging.
    ExtensionName() string
    // Validate is called when adding an extension to the server, it allows validation against the servers schema.
    Validate(schema ExecutableSchema) error
}

type MapCache

MapCache is the simplest implementation of a cache, because it can not evict it should only be used in tests

type MapCache map[string]interface{}

func (MapCache) Add

func (m MapCache) Add(_ context.Context, key string, value interface{})

Add adds a value to the cache.

func (MapCache) Get

func (m MapCache) Get(_ context.Context, key string) (value interface{}, ok bool)

Get looks up a key's value from the cache.

type Marshaler

type Marshaler interface {
    MarshalGQL(w io.Writer)
}

func MarshalAny

func MarshalAny(v interface{}) Marshaler

func MarshalBoolean

func MarshalBoolean(b bool) Marshaler

func MarshalDuration

func MarshalDuration(d time.Duration) Marshaler

MarshalDuration returns the duration on ISO8601 format

func MarshalFloat

func MarshalFloat(f float64) Marshaler

func MarshalID

func MarshalID(s string) Marshaler

func MarshalInt

func MarshalInt(i int) Marshaler

func MarshalInt32

func MarshalInt32(i int32) Marshaler

func MarshalInt64

func MarshalInt64(i int64) Marshaler

func MarshalIntID

func MarshalIntID(i int) Marshaler

func MarshalMap

func MarshalMap(val map[string]interface{}) Marshaler

func MarshalString

func MarshalString(s string) Marshaler

func MarshalTime

func MarshalTime(t time.Time) Marshaler

func MarshalUUID

func MarshalUUID(id uuid.UUID) Marshaler

func MarshalUint

func MarshalUint(i uint) Marshaler

func MarshalUint32

func MarshalUint32(i uint32) Marshaler

func MarshalUint64

func MarshalUint64(i uint64) Marshaler

func MarshalUpload

func MarshalUpload(f Upload) Marshaler

func WrapContextMarshaler

func WrapContextMarshaler(ctx context.Context, m ContextMarshaler) Marshaler

type Mutation

type Mutation struct{}

type NoCache

type NoCache struct{}

func (NoCache) Add

func (n NoCache) Add(_ context.Context, _ string, _ interface{})

func (NoCache) Get

func (n NoCache) Get(_ context.Context, _ string) (value interface{}, ok bool)

type Omittable

Omittable is a wrapper around a value that also stores whether it is set or not.

type Omittable[T any] struct {
    // contains filtered or unexported fields
}

func OmittableOf

func OmittableOf[T any](value T) Omittable[T]

func (Omittable[T]) IsSet

func (o Omittable[T]) IsSet() bool

func (Omittable[T]) MarshalJSON

func (o Omittable[T]) MarshalJSON() ([]byte, error)

func (*Omittable[T]) UnmarshalJSON

func (o *Omittable[T]) UnmarshalJSON(bytes []byte) error

func (Omittable[T]) Value

func (o Omittable[T]) Value() T

func (Omittable[T]) ValueOK

func (o Omittable[T]) ValueOK() (T, bool)

type OperationContext

type OperationContext struct {
    RawQuery      string
    Variables     map[string]interface{}
    OperationName string
    Doc           *ast.QueryDocument
    Headers       http.Header

    Operation              *ast.OperationDefinition
    DisableIntrospection   bool
    RecoverFunc            RecoverFunc
    ResolverMiddleware     FieldMiddleware
    RootResolverMiddleware RootFieldMiddleware

    Stats Stats
}

func GetOperationContext

func GetOperationContext(ctx context.Context) *OperationContext

func (*OperationContext) Error

func (c *OperationContext) Error(ctx context.Context, err error)

Error add error or multiple errors (if underlaying type is gqlerror.List) into the stack. Then it will be sends to the client, passing it through the formatter.

func (*OperationContext) Errorf

func (c *OperationContext) Errorf(ctx context.Context, format string, args ...interface{})

Errorf sends an error string to the client, passing it through the formatter. Deprecated: use graphql.AddErrorf(ctx, err) instead

func (*OperationContext) Recover

func (c *OperationContext) Recover(ctx context.Context, err interface{}) error

func (*OperationContext) Validate

func (c *OperationContext) Validate(ctx context.Context) error

type OperationContextMutator

OperationContextMutator is called after creating the request context, but before executing the root resolver.

type OperationContextMutator interface {
    MutateOperationContext(ctx context.Context, rc *OperationContext) *gqlerror.Error
}

type OperationHandler

type OperationHandler func(ctx context.Context) ResponseHandler

type OperationInterceptor

OperationInterceptor is called for each incoming query, for basic requests the writer will be invoked once, for subscriptions it will be invoked multiple times.

type OperationInterceptor interface {
    InterceptOperation(ctx context.Context, next OperationHandler) ResponseHandler
}

type OperationMiddleware

type OperationMiddleware func(ctx context.Context, next OperationHandler) ResponseHandler

type OperationParameterMutator

OperationParameterMutator is called before creating a request context. allows manipulating the raw query on the way in.

type OperationParameterMutator interface {
    MutateOperationParameters(ctx context.Context, request *RawParams) *gqlerror.Error
}

type PathContext

type PathContext struct {
    ParentField *FieldContext
    Parent      *PathContext
    Field       *string
    Index       *int
}

func GetPathContext

func GetPathContext(ctx context.Context) *PathContext

func NewPathWithField

func NewPathWithField(field string) *PathContext

func NewPathWithIndex

func NewPathWithIndex(index int) *PathContext

func (*PathContext) Path

func (fic *PathContext) Path() ast.Path

type Query

type Query struct{}

type RawParams

type RawParams struct {
    Query         string                 `json:"query"`
    OperationName string                 `json:"operationName"`
    Variables     map[string]interface{} `json:"variables"`
    Extensions    map[string]interface{} `json:"extensions"`
    Headers       http.Header            `json:"headers"`

    ReadTime TraceTiming `json:"-"`
}

func (*RawParams) AddUpload

func (p *RawParams) AddUpload(upload Upload, key, path string) *gqlerror.Error

type RecoverFunc

type RecoverFunc func(ctx context.Context, err interface{}) (userMessage error)

type RequestContext

Deprecated: Please update all references to OperationContext instead

type RequestContext = OperationContext

func GetRequestContext

func GetRequestContext(ctx context.Context) *RequestContext

Deprecated: Please update all references to GetOperationContext instead

type Resolver

type Resolver func(ctx context.Context) (res interface{}, err error)

type ResolverContext

Deprecated: Use FieldContext instead

type ResolverContext = FieldContext

func GetResolverContext

func GetResolverContext(ctx context.Context) *ResolverContext

Deprecated: Use GetFieldContext instead

type Response

Errors are intentionally serialized first based on the advice in https://github.com/facebook/graphql/commit/7b40390d48680b15cb93e02d46ac5eb249689876#diff-757cea6edf0288677a9eea4cfc801d87R107 and https://github.com/facebook/graphql/pull/384

type Response struct {
    Errors     gqlerror.List          `json:"errors,omitempty"`
    Data       json.RawMessage        `json:"data"`
    Label      string                 `json:"label,omitempty"`
    Path       ast.Path               `json:"path,omitempty"`
    HasNext    *bool                  `json:"hasNext,omitempty"`
    Extensions map[string]interface{} `json:"extensions,omitempty"`
}

func ErrorResponse

func ErrorResponse(ctx context.Context, messagef string, args ...interface{}) *Response

type ResponseHandler

type ResponseHandler func(ctx context.Context) *Response

func OneShot

func OneShot(resp *Response) ResponseHandler

type ResponseInterceptor

ResponseInterceptor is called around each graphql operation response. This can be called many times for a single operation the case of subscriptions.

type ResponseInterceptor interface {
    InterceptResponse(ctx context.Context, next ResponseHandler) *Response
}

type ResponseMiddleware

type ResponseMiddleware func(ctx context.Context, next ResponseHandler) *Response

type RootFieldContext

type RootFieldContext struct {
    // The name of the type this field belongs to
    Object string
    // The raw field
    Field CollectedField
}

func GetRootFieldContext

func GetRootFieldContext(ctx context.Context) *RootFieldContext

type RootFieldInterceptor

type RootFieldInterceptor interface {
    InterceptRootField(ctx context.Context, next RootResolver) Marshaler
}

type RootFieldMiddleware

type RootFieldMiddleware func(ctx context.Context, next RootResolver) Marshaler

type RootResolver

type RootResolver func(ctx context.Context) Marshaler

type Stats

type Stats struct {
    OperationStart time.Time
    Read           TraceTiming
    Parsing        TraceTiming
    Validation     TraceTiming
    // contains filtered or unexported fields
}

func (*Stats) GetExtension

func (c *Stats) GetExtension(name string) interface{}

func (*Stats) SetExtension

func (c *Stats) SetExtension(name string, data interface{})

type Status

type Status int

type Subscription

type Subscription struct{}

type TraceTiming

type TraceTiming struct {
    Start time.Time
    End   time.Time
}

type Transport

Transport provides support for different wire level encodings of graphql requests, eg Form, Get, Post, Websocket

type Transport interface {
    Supports(r *http.Request) bool
    Do(w http.ResponseWriter, r *http.Request, exec GraphExecutor)
}

type Unmarshaler

type Unmarshaler interface {
    UnmarshalGQL(v interface{}) error
}

type Upload

type Upload struct {
    File        io.ReadSeeker
    Filename    string
    Size        int64
    ContentType string
}

func UnmarshalUpload

func UnmarshalUpload(v interface{}) (Upload, error)

type WriterFunc

type WriterFunc func(writer io.Writer)

func (WriterFunc) MarshalGQL

func (f WriterFunc) MarshalGQL(w io.Writer)

Subdirectories

Name Synopsis
..
errcode
executor
testexecutor
handler
apollofederatedtracingv1
generated
apollotracing
debug
extension
lru
testserver
transport
introspection introspection implements the spec defined in https://github.com/facebook/graphql/blob/master/spec/Section%204%20--%20Introspection.md#schema-introspection
playground