aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/vektah/gqlgen/graphql/error.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-29 18:11:33 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-29 18:51:56 +0200
commit6363518c85cbd8247a5f6507b8a1dd3903cfb71d (patch)
treeaa51652e9881196b3637247988cbd5155f42b5e2 /vendor/github.com/vektah/gqlgen/graphql/error.go
parentff2fd14e3f10a7206d4ec86f07e524cfa290e0fc (diff)
downloadgit-bug-6363518c85cbd8247a5f6507b8a1dd3903cfb71d.tar.gz
relay connection working with gqlgen
Diffstat (limited to 'vendor/github.com/vektah/gqlgen/graphql/error.go')
-rw-r--r--vendor/github.com/vektah/gqlgen/graphql/error.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/vektah/gqlgen/graphql/error.go b/vendor/github.com/vektah/gqlgen/graphql/error.go
new file mode 100644
index 00000000..15e65fab
--- /dev/null
+++ b/vendor/github.com/vektah/gqlgen/graphql/error.go
@@ -0,0 +1,46 @@
+package graphql
+
+import (
+ "context"
+)
+
+// Error is the standard graphql error type described in https://facebook.github.io/graphql/draft/#sec-Errors
+type Error struct {
+ Message string `json:"message"`
+ Path []interface{} `json:"path,omitempty"`
+ Locations []ErrorLocation `json:"locations,omitempty"`
+ Extensions map[string]interface{} `json:"extensions,omitempty"`
+}
+
+func (e *Error) Error() string {
+ return e.Message
+}
+
+type ErrorLocation struct {
+ Line int `json:"line,omitempty"`
+ Column int `json:"column,omitempty"`
+}
+
+type ErrorPresenterFunc func(context.Context, error) *Error
+
+type ExtendedError interface {
+ Extensions() map[string]interface{}
+}
+
+func DefaultErrorPresenter(ctx context.Context, err error) *Error {
+ if gqlerr, ok := err.(*Error); ok {
+ gqlerr.Path = GetResolverContext(ctx).Path
+ return gqlerr
+ }
+
+ var extensions map[string]interface{}
+ if ee, ok := err.(ExtendedError); ok {
+ extensions = ee.Extensions()
+ }
+
+ return &Error{
+ Message: err.Error(),
+ Path: GetResolverContext(ctx).Path,
+ Extensions: extensions,
+ }
+}