diff --git a/executor.go b/executor.go index d8477140..12d401c4 100644 --- a/executor.go +++ b/executor.go @@ -650,15 +650,15 @@ func resolveField(eCtx *executionContext, parentType *Object, source interface{} Context: eCtx.Context, }) - if resolveFnError != nil { - panic(resolveFnError) - } - extErrs = resolveFieldFinishFn(result, resolveFnError) if len(extErrs) != 0 { eCtx.Errors = append(eCtx.Errors, extErrs...) } + if resolveFnError != nil { + panic(resolveFnError) + } + completed := completeValueCatchingError(eCtx, returnType, fieldASTs, info, path, result) return completed, resultState } diff --git a/extensions_test.go b/extensions_test.go index db7551ec..ea23f752 100644 --- a/extensions_test.go +++ b/extensions_test.go @@ -23,6 +23,12 @@ func tinit(t *testing.T) graphql.Schema { return "foo", nil }, }, + "erred": &graphql.Field{ + Type: graphql.String, + Resolve: func(p graphql.ResolveParams) (interface{}, error) { + return "", errors.New("ooops") + }, + }, }, }), }) @@ -306,6 +312,35 @@ func TestExtensionResolveFieldFinishFuncPanic(t *testing.T) { } } +func TestExtensionResolveFieldFinishFuncAfterError(t *testing.T) { + var fnErrs int + ext := newtestExt("testExt") + ext.resolveFieldDidStartFn = func(ctx context.Context, i *graphql.ResolveInfo) (context.Context, graphql.ResolveFieldFinishFunc) { + return ctx, func(v interface{}, err error) { + if err != nil { + fnErrs++ + } + } + } + + schema := tinit(t) + query := `query Example { erred }` + schema.AddExtensions(ext) + + result := graphql.Do(graphql.Params{ + Schema: schema, + RequestString: query, + }) + + if resErrs := len(result.Errors); resErrs != 1 { + t.Errorf("Incorrect number of returned result errors: %d", resErrs) + } + + if fnErrs != 1 { + t.Errorf("Incorrect number of errors captured: %d", fnErrs) + } +} + func TestExtensionGetResultPanic(t *testing.T) { ext := newtestExt("testExt") ext.getResultFn = func(context.Context) interface{} {