Skip to content

Commit 4ee17d6

Browse files
committed
adds OriginalError support
1 parent ef0eacf commit 4ee17d6

File tree

5 files changed

+565
-361
lines changed

5 files changed

+565
-361
lines changed

abstract_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
491491
}
492492
}`
493493

494+
originalError := gqlerrors.NewFormattedError(`Runtime Object type "Human" is not a possible type for "Pet".`)
494495
expected := &graphql.Result{
495496
Data: map[string]interface{}{
496497
"pets": []interface{}{
@@ -505,27 +506,27 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
505506
nil,
506507
},
507508
},
508-
Errors: []gqlerrors.FormattedError{
509-
{
510-
Message: `Runtime Object type "Human" is not a possible type for "Pet".`,
511-
Locations: []location.SourceLocation{
512-
{
513-
Line: 2,
514-
Column: 7,
515-
},
516-
},
517-
Path: []interface{}{
518-
"pets",
519-
2,
509+
Errors: []gqlerrors.FormattedError{gqlerrors.FormatError(gqlerrors.Error{
510+
Message: originalError.Message,
511+
Locations: []location.SourceLocation{
512+
{
513+
Line: 2,
514+
Column: 7,
520515
},
521516
},
522-
},
517+
Path: []interface{}{
518+
"pets",
519+
2,
520+
},
521+
OriginalError: originalError,
522+
})},
523523
}
524524

525525
result := graphql.Do(graphql.Params{
526526
Schema: schema,
527527
RequestString: query,
528528
})
529+
529530
if len(result.Errors) == 0 {
530531
t.Fatalf("wrong result, expected errors: %v, got: %v", len(expected.Errors), len(result.Errors))
531532
}
@@ -618,6 +619,7 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
618619
}
619620
}`
620621

622+
originalError := gqlerrors.NewFormattedError(`Runtime Object type "Human" is not a possible type for "Pet".`)
621623
expected := &graphql.Result{
622624
Data: map[string]interface{}{
623625
"pets": []interface{}{
@@ -633,8 +635,8 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
633635
},
634636
},
635637
Errors: []gqlerrors.FormattedError{
636-
{
637-
Message: `Runtime Object type "Human" is not a possible type for "Pet".`,
638+
gqlerrors.FormatError(gqlerrors.Error{
639+
Message: originalError.Message,
638640
Locations: []location.SourceLocation{
639641
{
640642
Line: 2,
@@ -645,7 +647,8 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
645647
"pets",
646648
2,
647649
},
648-
},
650+
OriginalError: originalError,
651+
}),
649652
},
650653
}
651654

executor_test.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -515,18 +515,19 @@ func TestNullsOutErrorSubtrees(t *testing.T) {
515515
"sync": "sync",
516516
"syncError": nil,
517517
}
518-
expectedErrors := []gqlerrors.FormattedError{
519-
{
520-
Message: "Error getting syncError",
521-
Locations: []location.SourceLocation{
522-
{
523-
Line: 3, Column: 7,
524-
},
525-
},
526-
Path: []interface{}{
527-
"syncError",
518+
originalError := errors.New("Error getting syncError")
519+
expectedErrors := []gqlerrors.FormattedError{gqlerrors.FormatError(gqlerrors.Error{
520+
Message: originalError.Error(),
521+
Locations: []location.SourceLocation{
522+
{
523+
Line: 3, Column: 7,
528524
},
529525
},
526+
Path: []interface{}{
527+
"syncError",
528+
},
529+
OriginalError: originalError,
530+
}),
530531
}
531532

532533
data := map[string]interface{}{
@@ -1296,6 +1297,7 @@ func TestFailsWhenAnIsTypeOfCheckIsNotMet(t *testing.T) {
12961297
},
12971298
}
12981299

1300+
originalError := gqlerrors.NewFormattedError(`Expected value of type "SpecialType" but got: graphql_test.testNotSpecialType.`)
12991301
expected := &graphql.Result{
13001302
Data: map[string]interface{}{
13011303
"specials": []interface{}{
@@ -1305,21 +1307,20 @@ func TestFailsWhenAnIsTypeOfCheckIsNotMet(t *testing.T) {
13051307
nil,
13061308
},
13071309
},
1308-
Errors: []gqlerrors.FormattedError{
1309-
{
1310-
Message: `Expected value of type "SpecialType" but got: graphql_test.testNotSpecialType.`,
1311-
Locations: []location.SourceLocation{
1312-
{
1313-
Line: 1,
1314-
Column: 3,
1315-
},
1316-
},
1317-
Path: []interface{}{
1318-
"specials",
1319-
1,
1310+
Errors: []gqlerrors.FormattedError{gqlerrors.FormatError(gqlerrors.Error{
1311+
Message: originalError.Message,
1312+
Locations: []location.SourceLocation{
1313+
{
1314+
Line: 1,
1315+
Column: 3,
13201316
},
13211317
},
1322-
},
1318+
Path: []interface{}{
1319+
"specials",
1320+
1,
1321+
},
1322+
OriginalError: originalError,
1323+
})},
13231324
}
13241325

13251326
specialType := graphql.NewObject(graphql.ObjectConfig{

gqlerrors/formatted.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func FormatError(err error) FormattedError {
4141
Message: err.Error(),
4242
Locations: err.Locations,
4343
Path: err.Path,
44-
originalError: err,
44+
originalError: err.OriginalError,
4545
}
4646
if err := err.OriginalError; err != nil {
4747
if extended, ok := err.(ExtendedError); ok {

0 commit comments

Comments
 (0)