Skip to content

Commit b6b24cf

Browse files
authored
Merge branch 'master' into master
2 parents e3a0caf + d925012 commit b6b24cf

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

executor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,15 @@ func resolveField(eCtx *executionContext, parentType *Object, source interface{}
653653
Context: eCtx.Context,
654654
})
655655

656-
if resolveFnError != nil {
657-
panic(resolveFnError)
658-
}
659-
660656
extErrs = resolveFieldFinishFn(result, resolveFnError)
661657
if len(extErrs) != 0 {
662658
eCtx.Errors = append(eCtx.Errors, extErrs...)
663659
}
664660

661+
if resolveFnError != nil {
662+
panic(resolveFnError)
663+
}
664+
665665
completed := completeValueCatchingError(eCtx, returnType, fieldASTs, info, path, result)
666666
return completed, resultState
667667
}

extensions_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func tinit(t *testing.T) graphql.Schema {
2323
return "foo", nil
2424
},
2525
},
26+
"erred": &graphql.Field{
27+
Type: graphql.String,
28+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
29+
return "", errors.New("ooops")
30+
},
31+
},
2632
},
2733
}),
2834
})
@@ -306,6 +312,35 @@ func TestExtensionResolveFieldFinishFuncPanic(t *testing.T) {
306312
}
307313
}
308314

315+
func TestExtensionResolveFieldFinishFuncAfterError(t *testing.T) {
316+
var fnErrs int
317+
ext := newtestExt("testExt")
318+
ext.resolveFieldDidStartFn = func(ctx context.Context, i *graphql.ResolveInfo) (context.Context, graphql.ResolveFieldFinishFunc) {
319+
return ctx, func(v interface{}, err error) {
320+
if err != nil {
321+
fnErrs++
322+
}
323+
}
324+
}
325+
326+
schema := tinit(t)
327+
query := `query Example { erred }`
328+
schema.AddExtensions(ext)
329+
330+
result := graphql.Do(graphql.Params{
331+
Schema: schema,
332+
RequestString: query,
333+
})
334+
335+
if resErrs := len(result.Errors); resErrs != 1 {
336+
t.Errorf("Incorrect number of returned result errors: %d", resErrs)
337+
}
338+
339+
if fnErrs != 1 {
340+
t.Errorf("Incorrect number of errors captured: %d", fnErrs)
341+
}
342+
}
343+
309344
func TestExtensionGetResultPanic(t *testing.T) {
310345
ext := newtestExt("testExt")
311346
ext.getResultFn = func(context.Context) interface{} {

0 commit comments

Comments
 (0)