aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/graphql/context.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-12-23 17:11:37 +0100
committerMichael Muré <batolettre@gmail.com>2018-12-23 17:11:37 +0100
commit1410a1af75b1ab9ea3f980a7e372728f9a123abf (patch)
treee24db8f84c48b20158b1f1fd6d281d700421279c /vendor/github.com/99designs/gqlgen/graphql/context.go
parent8fc15a032f021c855abf66ed303c003d57c340ea (diff)
downloadgit-bug-1410a1af75b1ab9ea3f980a7e372728f9a123abf.tar.gz
upgrade gqlgen to v0.7.1
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/graphql/context.go')
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/context.go45
1 files changed, 43 insertions, 2 deletions
diff --git a/vendor/github.com/99designs/gqlgen/graphql/context.go b/vendor/github.com/99designs/gqlgen/graphql/context.go
index 6baee83c..f83fa36f 100644
--- a/vendor/github.com/99designs/gqlgen/graphql/context.go
+++ b/vendor/github.com/99designs/gqlgen/graphql/context.go
@@ -17,6 +17,11 @@ type RequestContext struct {
RawQuery string
Variables map[string]interface{}
Doc *ast.QueryDocument
+
+ ComplexityLimit int
+ OperationComplexity int
+ DisableIntrospection bool
+
// ErrorPresenter will be used to generate the error
// message from errors given to Error().
ErrorPresenter ErrorPresenterFunc
@@ -24,9 +29,12 @@ type RequestContext struct {
ResolverMiddleware FieldMiddleware
DirectiveMiddleware FieldMiddleware
RequestMiddleware RequestMiddleware
+ Tracer Tracer
- errorsMu sync.Mutex
- Errors gqlerror.List
+ errorsMu sync.Mutex
+ Errors gqlerror.List
+ extensionsMu sync.Mutex
+ Extensions map[string]interface{}
}
func DefaultResolverMiddleware(ctx context.Context, next Resolver) (res interface{}, err error) {
@@ -51,6 +59,7 @@ func NewRequestContext(doc *ast.QueryDocument, query string, variables map[strin
RequestMiddleware: DefaultRequestMiddleware,
Recover: DefaultRecover,
ErrorPresenter: DefaultErrorPresenter,
+ Tracer: &NopTracer{},
}
}
@@ -153,6 +162,21 @@ func (c *RequestContext) HasError(rctx *ResolverContext) bool {
return false
}
+// GetErrors returns a list of errors that occurred in the current field
+func (c *RequestContext) GetErrors(rctx *ResolverContext) gqlerror.List {
+ c.errorsMu.Lock()
+ defer c.errorsMu.Unlock()
+ path := rctx.Path()
+
+ var errs gqlerror.List
+ for _, err := range c.Errors {
+ if equalPath(err.Path, path) {
+ errs = append(errs, err)
+ }
+ }
+ return errs
+}
+
func equalPath(a []interface{}, b []interface{}) bool {
if len(a) != len(b) {
return false
@@ -176,3 +200,20 @@ func AddError(ctx context.Context, err error) {
func AddErrorf(ctx context.Context, format string, args ...interface{}) {
GetRequestContext(ctx).Errorf(ctx, format, args...)
}
+
+// RegisterExtension registers an extension, returns error if extension has already been registered
+func (c *RequestContext) RegisterExtension(key string, value interface{}) error {
+ c.extensionsMu.Lock()
+ defer c.extensionsMu.Unlock()
+
+ if c.Extensions == nil {
+ c.Extensions = make(map[string]interface{})
+ }
+
+ if _, ok := c.Extensions[key]; ok {
+ return fmt.Errorf("extension already registered for key %s", key)
+ }
+
+ c.Extensions[key] = value
+ return nil
+}