Documentation ¶
Index ¶
- func InvokeMiddleware(middleware GraphqlMiddleware, ctx context.Context, schema, request string) (result string, err error)
- type ContextMiddleware
- func (a *ContextMiddleware) OnRequest(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, ...) error
- func (a *ContextMiddleware) OnResponse(ctx context.Context, response *[]byte, l *lookup.Lookup, w *lookup.Walker, ...) (err error)
- func (a *ContextMiddleware) PrepareSchema(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, ...) error
- type ContextRewriteConfig
- type GraphQLRequest
- type GraphqlMiddleware
- type Invoker
- type InvokerPool
- type ValidationMiddleware
- func (v *ValidationMiddleware) OnRequest(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, ...) error
- func (v *ValidationMiddleware) OnResponse(ctx context.Context, response *[]byte, l *lookup.Lookup, w *lookup.Walker, ...) (err error)
- func (v *ValidationMiddleware) PrepareSchema(ctx context.Context, l *lookup.Lookup, w *lookup.Walker, parser *parser.Parser, ...) error
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) OnResponse ¶
func (*ContextMiddleware) PrepareSchema ¶ added in v1.6.0
type ContextRewriteConfig ¶
type ContextRewriteConfig struct {
// contains filtered or unexported fields
}
type GraphQLRequest ¶ added in v1.6.2
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 ¶
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) OnResponse ¶ added in v1.4.0
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