aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/graphql
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
parent8fc15a032f021c855abf66ed303c003d57c340ea (diff)
downloadgit-bug-1410a1af75b1ab9ea3f980a7e372728f9a123abf.tar.gz
upgrade gqlgen to v0.7.1
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/graphql')
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/context.go45
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/float.go2
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/introspection/introspection.go52
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/introspection/type.go18
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/response.go8
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/tracer.go58
-rw-r--r--vendor/github.com/99designs/gqlgen/graphql/version.go2
7 files changed, 150 insertions, 35 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
+}
diff --git a/vendor/github.com/99designs/gqlgen/graphql/float.go b/vendor/github.com/99designs/gqlgen/graphql/float.go
index d204335c..fabbad04 100644
--- a/vendor/github.com/99designs/gqlgen/graphql/float.go
+++ b/vendor/github.com/99designs/gqlgen/graphql/float.go
@@ -9,7 +9,7 @@ import (
func MarshalFloat(f float64) Marshaler {
return WriterFunc(func(w io.Writer) {
- io.WriteString(w, fmt.Sprintf("%f", f))
+ io.WriteString(w, fmt.Sprintf("%g", f))
})
}
diff --git a/vendor/github.com/99designs/gqlgen/graphql/introspection/introspection.go b/vendor/github.com/99designs/gqlgen/graphql/introspection/introspection.go
index baff882e..ca0b065f 100644
--- a/vendor/github.com/99designs/gqlgen/graphql/introspection/introspection.go
+++ b/vendor/github.com/99designs/gqlgen/graphql/introspection/introspection.go
@@ -12,19 +12,17 @@ type (
}
EnumValue struct {
- Name string
- Description string
- IsDeprecated bool
- DeprecationReason string
+ Name string
+ Description string
+ deprecation *ast.Directive
}
Field struct {
- Name string
- Description string
- Type *Type
- Args []InputValue
- IsDeprecated bool
- DeprecationReason string
+ Name string
+ Description string
+ Type *Type
+ Args []InputValue
+ deprecation *ast.Directive
}
InputValue struct {
@@ -39,20 +37,36 @@ func WrapSchema(schema *ast.Schema) *Schema {
return &Schema{schema: schema}
}
-func isDeprecated(directives ast.DirectiveList) bool {
- return directives.ForName("deprecated") != nil
+func (f *EnumValue) IsDeprecated() bool {
+ return f.deprecation != nil
+}
+
+func (f *EnumValue) DeprecationReason() *string {
+ if f.deprecation == nil {
+ return nil
+ }
+
+ reason := f.deprecation.Arguments.ForName("reason")
+ if reason == nil {
+ return nil
+ }
+
+ return &reason.Value.Raw
+}
+
+func (f *Field) IsDeprecated() bool {
+ return f.deprecation != nil
}
-func deprecationReason(directives ast.DirectiveList) string {
- deprecation := directives.ForName("deprecated")
- if deprecation == nil {
- return ""
+func (f *Field) DeprecationReason() *string {
+ if f.deprecation == nil {
+ return nil
}
- reason := deprecation.Arguments.ForName("reason")
+ reason := f.deprecation.Arguments.ForName("reason")
if reason == nil {
- return ""
+ return nil
}
- return reason.Value.Raw
+ return &reason.Value.Raw
}
diff --git a/vendor/github.com/99designs/gqlgen/graphql/introspection/type.go b/vendor/github.com/99designs/gqlgen/graphql/introspection/type.go
index dce144e0..b963aa0e 100644
--- a/vendor/github.com/99designs/gqlgen/graphql/introspection/type.go
+++ b/vendor/github.com/99designs/gqlgen/graphql/introspection/type.go
@@ -81,12 +81,11 @@ func (t *Type) Fields(includeDeprecated bool) []Field {
}
fields = append(fields, Field{
- Name: f.Name,
- Description: f.Description,
- Args: args,
- Type: WrapTypeFromType(t.schema, f.Type),
- IsDeprecated: isDeprecated(f.Directives),
- DeprecationReason: deprecationReason(f.Directives),
+ Name: f.Name,
+ Description: f.Description,
+ Args: args,
+ Type: WrapTypeFromType(t.schema, f.Type),
+ deprecation: f.Directives.ForName("deprecated"),
})
}
return fields
@@ -150,10 +149,9 @@ func (t *Type) EnumValues(includeDeprecated bool) []EnumValue {
var res []EnumValue
for _, val := range t.def.EnumValues {
res = append(res, EnumValue{
- Name: val.Name,
- Description: val.Description,
- IsDeprecated: isDeprecated(val.Directives),
- DeprecationReason: deprecationReason(val.Directives),
+ Name: val.Name,
+ Description: val.Description,
+ deprecation: val.Directives.ForName("deprecated"),
})
}
return res
diff --git a/vendor/github.com/99designs/gqlgen/graphql/response.go b/vendor/github.com/99designs/gqlgen/graphql/response.go
index 18664dca..6fe55d56 100644
--- a/vendor/github.com/99designs/gqlgen/graphql/response.go
+++ b/vendor/github.com/99designs/gqlgen/graphql/response.go
@@ -8,9 +8,13 @@ import (
"github.com/vektah/gqlparser/gqlerror"
)
+// Errors are intentionally serialized first based on the advice in
+// https://github.com/facebook/graphql/commit/7b40390d48680b15cb93e02d46ac5eb249689876#diff-757cea6edf0288677a9eea4cfc801d87R107
+// and https://github.com/facebook/graphql/pull/384
type Response struct {
- Data json.RawMessage `json:"data"`
- Errors gqlerror.List `json:"errors,omitempty"`
+ Errors gqlerror.List `json:"errors,omitempty"`
+ Data json.RawMessage `json:"data"`
+ Extensions map[string]interface{} `json:"extensions,omitempty"`
}
func ErrorResponse(ctx context.Context, messagef string, args ...interface{}) *Response {
diff --git a/vendor/github.com/99designs/gqlgen/graphql/tracer.go b/vendor/github.com/99designs/gqlgen/graphql/tracer.go
new file mode 100644
index 00000000..0597ce8c
--- /dev/null
+++ b/vendor/github.com/99designs/gqlgen/graphql/tracer.go
@@ -0,0 +1,58 @@
+package graphql
+
+import (
+ "context"
+)
+
+var _ Tracer = (*NopTracer)(nil)
+
+type Tracer interface {
+ StartOperationParsing(ctx context.Context) context.Context
+ EndOperationParsing(ctx context.Context)
+ StartOperationValidation(ctx context.Context) context.Context
+ EndOperationValidation(ctx context.Context)
+ StartOperationExecution(ctx context.Context) context.Context
+ StartFieldExecution(ctx context.Context, field CollectedField) context.Context
+ StartFieldResolverExecution(ctx context.Context, rc *ResolverContext) context.Context
+ StartFieldChildExecution(ctx context.Context) context.Context
+ EndFieldExecution(ctx context.Context)
+ EndOperationExecution(ctx context.Context)
+}
+
+type NopTracer struct{}
+
+func (NopTracer) StartOperationParsing(ctx context.Context) context.Context {
+ return ctx
+}
+
+func (NopTracer) EndOperationParsing(ctx context.Context) {
+}
+
+func (NopTracer) StartOperationValidation(ctx context.Context) context.Context {
+ return ctx
+}
+
+func (NopTracer) EndOperationValidation(ctx context.Context) {
+}
+
+func (NopTracer) StartOperationExecution(ctx context.Context) context.Context {
+ return ctx
+}
+
+func (NopTracer) StartFieldExecution(ctx context.Context, field CollectedField) context.Context {
+ return ctx
+}
+
+func (NopTracer) StartFieldResolverExecution(ctx context.Context, rc *ResolverContext) context.Context {
+ return ctx
+}
+
+func (NopTracer) StartFieldChildExecution(ctx context.Context) context.Context {
+ return ctx
+}
+
+func (NopTracer) EndFieldExecution(ctx context.Context) {
+}
+
+func (NopTracer) EndOperationExecution(ctx context.Context) {
+}
diff --git a/vendor/github.com/99designs/gqlgen/graphql/version.go b/vendor/github.com/99designs/gqlgen/graphql/version.go
index 38d3720b..8cf3c9ba 100644
--- a/vendor/github.com/99designs/gqlgen/graphql/version.go
+++ b/vendor/github.com/99designs/gqlgen/graphql/version.go
@@ -1,3 +1,3 @@
package graphql
-const Version = "v0.5.1"
+const Version = "dev"