forked from graph-gophers/graphql-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.go
26 lines (22 loc) · 961 Bytes
/
middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package graphql
import (
"context"
"github.com/graph-gophers/graphql-go/errors"
"github.com/graph-gophers/graphql-go/internal/exec/resolvable"
)
// Exec executes the given query with the schema's resolver.
type Exec func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response
// Middleware can wrap Exec to add additional behaviour
type Middleware func(next Exec) Exec
func ParseErrorsMiddleware(parseErrors func([]*errors.QueryError) []*errors.QueryError) Middleware {
return func(next Exec) Exec {
return func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response {
// perform the original query
response := next(ctx, queryString, operationName, variables, res)
// mutate the errors
response.Errors = parseErrors(response.Errors)
// return the response
return response
}
}
}