Documentation ¶
Index ¶
- Constants
- Variables
- func AddError(ctx context.Context, err error)
- func AddErrorf(ctx context.Context, format string, args ...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 UnmarshalFloat(v interface{}) (float64, error)
- func UnmarshalID(v interface{}) (string, 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 WithFieldContext(ctx context.Context, rc *FieldContext) 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
- type Array
- type Cache
- type CollectedField
- type ErrorPresenterFunc
- type ExecutableSchema
- type ExecutableSchemaMock
- func (mock *ExecutableSchemaMock) Complexity(typeName string, fieldName string, childComplexity int, ...) (int, bool)
- func (mock *ExecutableSchemaMock) ComplexityCalls() []struct{ ... }
- func (mock *ExecutableSchemaMock) Exec(ctx context.Context) ResponseHandler
- func (mock *ExecutableSchemaMock) ExecCalls() []struct{ ... }
- func (mock *ExecutableSchemaMock) Schema() *ast.Schema
- func (mock *ExecutableSchemaMock) SchemaCalls() []struct{}
- type FieldContext
- type FieldInterceptor
- type FieldMiddleware
- type FieldSet
- type FieldStats
- type GraphExecutor
- type HandlerExtension
- type MapCache
- type Marshaler
- func MarshalAny(v interface{}) Marshaler
- func MarshalBoolean(b bool) 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 MarshalUpload(f Upload) Marshaler
- type Mutation
- type NoCache
- type OperationContext
- type OperationContextMutator
- type OperationHandler
- type OperationInterceptor
- type OperationMiddleware
- type OperationParameterMutator
- type PathContext
- type Query
- type RawParams
- type RecoverFunc
- type RequestContextdeprecated
- type Resolver
- type ResolverContextdeprecated
- type Response
- type ResponseHandler
- type ResponseInterceptor
- type ResponseMiddleware
- type Stats
- type Status
- type Subscription
- type TraceTiming
- type Transport
- type Unmarshaler
- type Upload
- type WriterFunc
Constants ¶
const Version = "v0.13.0"
Variables ¶
var False = &lit{falseLit}
var Now = time.Now
Now is time.Now, except in tests. Then it can be whatever you want it to be.
var Null = &lit{nullLit}
var True = &lit{trueLit}
Functions ¶
func AddError ¶
AddError sends an error to the client, first passing it through the error presenter.
func AddErrorf ¶
AddErrorf writes a formatted error to the client, first passing it through the error presenter.
func CollectAllFields ¶
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 DefaultRecover ¶
func GetExtension ¶
func GetExtensions ¶
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 GetStartTime ¶
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 ¶
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 RegisterExtension ¶
RegisterExtension allows you to add a new extension into the graphql response
func StartOperationTrace ¶
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 dont 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 UnmarshalFloat ¶
func UnmarshalID ¶
func UnmarshalInt ¶
func UnmarshalInt32 ¶
func UnmarshalInt64 ¶
func UnmarshalIntID ¶
func UnmarshalMap ¶
func UnmarshalString ¶
func UnmarshalTime ¶
func WithFieldContext ¶
func WithFieldContext(ctx context.Context, rc *FieldContext) 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
Types ¶
type Cache ¶
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{}) }
Cache is a shared store for APQ and query AST caching
type CollectedField ¶
type CollectedField struct { *ast.Field Selections ast.SelectionSet }
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 ErrorPresenterFunc ¶
type ExecutableSchema ¶
type ExecutableSchemaMock ¶
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 }
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. }
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 }
func GetFieldContext ¶
func GetFieldContext(ctx context.Context) *FieldContext
func (*FieldContext) Path ¶
func (r *FieldContext) Path() ast.Path
type FieldInterceptor ¶
type FieldInterceptor interface {
InterceptField(ctx context.Context, next Resolver) (res interface{}, err error)
}
FieldInterceptor called around each field
type FieldMiddleware ¶
type FieldSet ¶
type FieldSet struct { Values []Marshaler // contains filtered or unexported fields }
func NewFieldSet ¶
func NewFieldSet(fields []CollectedField) *FieldSet
func (*FieldSet) Concurrently ¶
func (*FieldSet) MarshalGQL ¶
type FieldStats ¶
type GraphExecutor ¶
type HandlerExtension ¶
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 }
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 MapCache ¶
type MapCache map[string]interface{}
MapCache is the simplest implementation of a cache, because it can not evict it should only be used in tests
type Marshaler ¶
func MarshalAny ¶
func MarshalAny(v interface{}) Marshaler
func MarshalBoolean ¶
func MarshalFloat ¶
func MarshalInt ¶
func MarshalInt32 ¶
func MarshalInt64 ¶
func MarshalIntID ¶
func MarshalMap ¶
func MarshalString ¶
func MarshalTime ¶
func MarshalUpload ¶
type OperationContext ¶
type OperationContext struct { RawQuery string Variables map[string]interface{} OperationName string Doc *ast.QueryDocument Operation *ast.OperationDefinition DisableIntrospection bool RecoverFunc RecoverFunc ResolverMiddleware FieldMiddleware Stats Stats }
func GetOperationContext ¶
func GetOperationContext(ctx context.Context) *OperationContext
func (*OperationContext) Error ¶
func (c *OperationContext) Error(ctx context.Context, err error)
Error sends an error to the client, passing it through the formatter. Deprecated: use graphql.AddError(ctx, err) instead
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
type OperationContextMutator ¶
type OperationContextMutator interface {
MutateOperationContext(ctx context.Context, rc *OperationContext) *gqlerror.Error
}
OperationContextMutator is called after creating the request context, but before executing the root resolver.
type OperationHandler ¶
type OperationHandler func(ctx context.Context) ResponseHandler
type OperationInterceptor ¶
type OperationInterceptor interface {
InterceptOperation(ctx context.Context, next OperationHandler) ResponseHandler
}
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 OperationMiddleware ¶
type OperationMiddleware func(ctx context.Context, next OperationHandler) ResponseHandler
type OperationParameterMutator ¶
type OperationParameterMutator interface {
MutateOperationParameters(ctx context.Context, request *RawParams) *gqlerror.Error
}
OperationParameterMutator is called before creating a request context. allows manipulating the raw query on the way in.
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 RawParams ¶
type RawParams struct { Query string `json:"query"` OperationName string `json:"operationName"` Variables map[string]interface{} `json:"variables"` Extensions map[string]interface{} `json:"extensions"` ReadTime TraceTiming `json:"-"` }
type RecoverFunc ¶
type RequestContext
deprecated
type RequestContext = OperationContext
Deprecated: Please update all references to OperationContext instead
func GetRequestContext
deprecated
func GetRequestContext(ctx context.Context) *RequestContext
Deprecated: Please update all references to GetOperationContext instead
type ResolverContext
deprecated
type ResolverContext = FieldContext
Deprecated: Use FieldContext instead
func GetResolverContext
deprecated
func GetResolverContext(ctx context.Context) *ResolverContext
Deprecated: Use GetFieldContext instead
type Response ¶
type Response struct { Errors gqlerror.List `json:"errors,omitempty"` Data json.RawMessage `json:"data"` Extensions map[string]interface{} `json:"extensions,omitempty"` }
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 ResponseHandler ¶
func OneShot ¶
func OneShot(resp *Response) ResponseHandler
type ResponseInterceptor ¶
type ResponseInterceptor interface {
InterceptResponse(ctx context.Context, next ResponseHandler) *Response
}
ResponseInterceptor is called around each graphql operation response. This can be called many times for a single operation the case of subscriptions.
type ResponseMiddleware ¶
type ResponseMiddleware func(ctx context.Context, next ResponseHandler) *Response
type Stats ¶
type Stats struct { OperationStart time.Time Read TraceTiming Parsing TraceTiming Validation TraceTiming // contains filtered or unexported fields }
func (*Stats) GetExtension ¶
func (*Stats) SetExtension ¶
type Subscription ¶
type Subscription struct{}
type Transport ¶
type Transport interface { Supports(r *http.Request) bool Do(w http.ResponseWriter, r *http.Request, exec GraphExecutor) }
Transport provides support for different wire level encodings of graphql requests, eg Form, Get, Post, Websocket
type Unmarshaler ¶
type Unmarshaler interface {
UnmarshalGQL(v interface{}) error
}
type Upload ¶
func UnmarshalUpload ¶
type WriterFunc ¶
func (WriterFunc) MarshalGQL ¶
func (f WriterFunc) MarshalGQL(w io.Writer)
Source Files ¶
- any.go
- bool.go
- cache.go
- context_field.go
- context_operation.go
- context_path.go
- context_response.go
- error.go
- executable_schema.go
- executable_schema_mock.go
- fieldset.go
- float.go
- handler.go
- id.go
- int.go
- jsonw.go
- map.go
- oneshot.go
- recovery.go
- response.go
- root.go
- stats.go
- string.go
- time.go
- upload.go
- version.go
Directories ¶
Path | Synopsis |
---|---|
introspection implements the spec defined in https://github.com/facebook/graphql/blob/master/spec/Section%204%20--%20Introspection.md#schema-introspection
|
introspection implements the spec defined in https://github.com/facebook/graphql/blob/master/spec/Section%204%20--%20Introspection.md#schema-introspection |