Back to godoc.org

Package handler

v1.0.27
Latest Go to latest

The latest major version is .

Published: Dec 12, 2019 | License: MIT | Module: git.chezaja.by/base/gqlgen

Index

Constants

const DefaultCacheSize = 1000
const DefaultConnectionKeepAlivePingInterval = 25 * time.Second
const DefaultUploadMaxMemory = 32 << 20

DefaultUploadMaxMemory is the maximum number of bytes used to parse a request body as multipart/form-data in memory, with the remainder stored on disk in temporary files.

const DefaultUploadMaxSize = 32 << 20

DefaultUploadMaxSize is maximum number of bytes used to parse a request body as multipart/form-data.

func GraphQL

func GraphQL(exec graphql.ExecutableSchema, options ...Option) http.HandlerFunc

func Playground

func Playground(title string, endpoint string) http.HandlerFunc

type Config

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

type InitPayload

type InitPayload map[string]interface{}

InitPayload is a structure that is parsed from the websocket init message payload. TO use request headers for non-websocket, instead wrap the graphql handler in a middleware.

func GetInitPayload

func GetInitPayload(ctx context.Context) InitPayload

GetInitPayload gets a map of the data sent with the connection_init message, which is used by graphql clients as a stand-in for HTTP headers.

func (InitPayload) Authorization

func (payload InitPayload) Authorization() string

Authorization is a short hand for getting the Authorization header from the payload.

func (InitPayload) GetString

func (payload InitPayload) GetString(key string) string

GetString safely gets a string value from the payload. It returns an empty string if the payload is nil or the value isn't set.

type Option

type Option func(cfg *Config)

func CacheSize

func CacheSize(size int) Option

CacheSize sets the maximum size of the query cache. If size is less than or equal to 0, the cache is disabled.

func ComplexityLimit

func ComplexityLimit(limit int) Option

ComplexityLimit sets a maximum query complexity that is allowed to be executed. If a query is submitted that exceeds the limit, a 422 status code will be returned.

func ComplexityLimitFunc

func ComplexityLimitFunc(complexityLimitFunc graphql.ComplexityLimitFunc) Option

ComplexityLimitFunc allows you to define a function to dynamically set the maximum query complexity that is allowed to be executed. If a query is submitted that exceeds the limit, a 422 status code will be returned.

func EnablePersistedQueryCache

func EnablePersistedQueryCache(cache PersistedQueryCache) Option

Add cache that will hold queries for automatic persisted queries (APQ)

func ErrorPresenter

func ErrorPresenter(f graphql.ErrorPresenterFunc) Option

ErrorPresenter transforms errors found while resolving into errors that will be returned to the user. It provides a good place to add any extra fields, like error.type, that might be desired by your frontend. Check the default implementation in graphql.DefaultErrorPresenter for an example.

func IntrospectionEnabled

func IntrospectionEnabled(enabled bool) Option

IntrospectionEnabled = false will forbid clients from calling introspection endpoints. Can be useful in prod when you dont want clients introspecting the full schema.

func RecoverFunc

func RecoverFunc(recover graphql.RecoverFunc) Option

func RequestMiddleware

func RequestMiddleware(middleware graphql.RequestMiddleware) Option

RequestMiddleware allows you to define a function that will be called around the root request, after the query has been parsed. This is useful for logging

func ResolverMiddleware

func ResolverMiddleware(middleware graphql.FieldMiddleware) Option

ResolverMiddleware allows you to define a function that will be called around every resolver, useful for logging.

func Tracer

func Tracer(tracer graphql.Tracer) Option

Tracer allows you to add a request/resolver tracer that will be called around the root request, calling resolver. This is useful for tracing

func UploadMaxMemory

func UploadMaxMemory(size int64) Option

UploadMaxMemory sets the maximum number of bytes used to parse a request body as multipart/form-data in memory, with the remainder stored on disk in temporary files.

func UploadMaxSize

func UploadMaxSize(size int64) Option

UploadMaxSize sets the maximum number of bytes used to parse a request body as multipart/form-data.

func WebsocketInitFunc

func WebsocketInitFunc(websocketInitFunc websocketInitFunc) Option

WebsocketInitFunc is called when the server receives connection init message from the client. This can be used to check initial payload to see whether to accept the websocket connection.

func WebsocketKeepAliveDuration

func WebsocketKeepAliveDuration(duration time.Duration) Option

WebsocketKeepAliveDuration allows you to reconfigure the keepalive behavior. By default, keepalive is enabled with a DefaultConnectionKeepAlivePingInterval duration. Set handler.connectionKeepAlivePingInterval = 0 to disable keepalive altogether.

func WebsocketUpgrader

func WebsocketUpgrader(upgrader websocket.Upgrader) Option

type PersistedQueryCache

type PersistedQueryCache interface {
	Add(ctx context.Context, hash string, query string)
	Get(ctx context.Context, hash string) (string, bool)
}

Package Files

  • context.go
  • graphql.go
  • mock.go
  • playground.go
  • stub.go
  • websocket.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier