From e878f87687766edff7ff2b822656625bca22328e Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 22 Jun 2020 15:59:36 +0800 Subject: [PATCH 1/2] More easier to extend error we can return our custom error which imply interface gqlerrors.ExtendedError instead of new a sqlerrors.Error --- gqlerrors/formatted.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gqlerrors/formatted.go b/gqlerrors/formatted.go index fb422b63..97266dae 100644 --- a/gqlerrors/formatted.go +++ b/gqlerrors/formatted.go @@ -52,11 +52,16 @@ func FormatError(err error) FormattedError { case Error: return FormatError(&err) default: - return FormattedError{ + ret := FormattedError{ Message: err.Error(), Locations: []location.SourceLocation{}, originalError: err, } + + if extended, ok := err.(ExtendedError); ok { + ret.Extensions = extended.Extensions() + } + return ret } } From a83a349668c35f8939fdc70647673e9f13982d1d Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 22 Jun 2020 16:15:20 +0800 Subject: [PATCH 2/2] invoid embed gqlerros.FormattedError too much --- executor.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/executor.go b/executor.go index 3c8441d2..3c558bff 100644 --- a/executor.go +++ b/executor.go @@ -703,7 +703,7 @@ func completeValue(eCtx *executionContext, returnType Type, fieldASTs []*ast.Fie FieldASTsToNodeASTs(fieldASTs), path.AsArray(), ) - panic(gqlerrors.FormatError(err)) + panic(err) } return completed } @@ -746,7 +746,7 @@ func completeValue(eCtx *executionContext, returnType Type, fieldASTs []*ast.Fie `Cannot complete value of unexpected type "%v."`, returnType) if err != nil { - panic(gqlerrors.FormatError(err)) + panic(err) } return nil } @@ -763,11 +763,11 @@ func completeThunkValueCatchingError(eCtx *executionContext, returnType Type, fi propertyFn, ok := result.(func() (interface{}, error)) if !ok { err := gqlerrors.NewFormattedError("Error resolving func. Expected `func() (interface{}, error)` signature") - panic(gqlerrors.FormatError(err)) + panic(err) } fnResult, err := propertyFn() if err != nil { - panic(gqlerrors.FormatError(err)) + panic(err) } result = fnResult @@ -892,7 +892,7 @@ func completeListValue(eCtx *executionContext, returnType *List, fieldASTs []*as "for field %v.%v.", parentTypeName, info.FieldName) if err != nil { - panic(gqlerrors.FormatError(err)) + panic(err) } itemType := returnType.OfType