middleware

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InvokeMiddleware

func InvokeMiddleware(middleware GraphqlMiddleware, ctx context.Context, schema, request string) (result string, err error)

InvokeMiddleware is a one off middleware invocation helper This should only be used for testing as it's a waste of resources It makes use of panics to don't use this in production!

Types

type ContextMiddleware

type ContextMiddleware struct {
}

ContextMiddleware does rewrite graphql requests based on schema annotations using a provided context object as input

example schema:

type Query {
	documents: [Document] @addArgumentFromContext(name: "user",contextKey: "user")
}

given there's an object with key "user" and value "jsmith@example.org" in the context

original Request:

query myDocuments {
	documents {
		sensitiveInformation
	}
}

Request after rewriting:

query myDocuments {
	documents(user: "jsmith@example.org") {
		sensitiveInformation
	}
}

func (*ContextMiddleware) OnRequest

func (a *ContextMiddleware) OnRequest(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) error

func (*ContextMiddleware) OnResponse

func (a *ContextMiddleware) OnResponse(ctx context.Context, response *[]byte, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) (err error)

func (*ContextMiddleware) PrepareSchema added in v1.6.0

func (a *ContextMiddleware) PrepareSchema(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) error

type ContextRewriteConfig

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

type GraphQLRequest added in v1.6.2

type GraphQLRequest struct {
	OperationName string                 `json:"operationName,omitempty"`
	Query         string                 `json:"query"`
	Variables     map[string]interface{} `json:"variables,omitempty"`
}

type GraphqlMiddleware

type GraphqlMiddleware interface {
	// PrepareSchema is used to bring the schema in a valid state
	// Example usages might be:
	// - adding necessary directives to the schema, e.g. adding the context directive so that the context middleware works
	// - define the graphql internal scalar types so that the validation middleware can do its thing
	PrepareSchema(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) error
	// OnRequest is the handler func for a request from the client
	// this can be used to transform the query and/or variables before sending it to the backend
	OnRequest(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) error
	// OnResponse is the handler func for the response from the backend server
	// this can be used to transform the response before sending the result back to the client
	OnResponse(ctx context.Context, response *[]byte, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) (err error)
}

GraphqlMiddleware is the interface to be implemented when writing middlewares

type Invoker

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

func NewInvoker

func NewInvoker(middleWares ...GraphqlMiddleware) *Invoker

func (*Invoker) InvokeMiddleWares

func (i *Invoker) InvokeMiddleWares(ctx context.Context, request []byte) (err error)

func (*Invoker) RewriteRequest

func (i *Invoker) RewriteRequest(w io.Writer) error

func (*Invoker) SetSchema

func (i *Invoker) SetSchema(schema []byte) error

type InvokerPool added in v1.4.0

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

func NewInvokerPool added in v1.4.0

func NewInvokerPool(size int, middleWares ...GraphqlMiddleware) *InvokerPool

func (*InvokerPool) Free added in v1.4.0

func (i *InvokerPool) Free(index int)

func (*InvokerPool) Get added in v1.4.0

func (i *InvokerPool) Get() (index int, invoker *Invoker)

type ValidationMiddleware added in v1.4.0

type ValidationMiddleware struct {
}

ValidationMiddleware is a middleware which validates the input Query against the Schema definition

func (*ValidationMiddleware) OnRequest added in v1.4.0

func (*ValidationMiddleware) OnResponse added in v1.4.0

func (v *ValidationMiddleware) OnResponse(ctx context.Context, response *[]byte, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) (err error)

func (*ValidationMiddleware) PrepareSchema added in v1.6.0

func (v *ValidationMiddleware) PrepareSchema(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, mod *parser.ManualAstMod) error

PrepareSchema adds the base scalar and directive types to the schema so that the user doesn't have to add them if we omit these definitions from the schema definition the validation will fail

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL