Skip to content

Commit 21fe71d

Browse files
authored
Merge pull request #427 from graphql-go/original-error-improvements
errors: consolidates original error for re-usability
2 parents 0894364 + 79ad586 commit 21fe71d

11 files changed

+480
-845
lines changed

abstract_test.go

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

494-
originalError := gqlerrors.NewFormattedError(`Runtime Object type "Human" is not a possible type for "Pet".`)
495494
expected := &graphql.Result{
496495
Data: map[string]interface{}{
497496
"pets": []interface{}{
@@ -506,31 +505,28 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
506505
nil,
507506
},
508507
},
509-
Errors: []gqlerrors.FormattedError{gqlerrors.FormatError(gqlerrors.Error{
510-
Message: originalError.Message,
511-
Locations: []location.SourceLocation{
512-
{
513-
Line: 2,
514-
Column: 7,
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,
515520
},
516521
},
517-
Path: []interface{}{
518-
"pets",
519-
2,
520-
},
521-
OriginalError: originalError,
522-
})},
522+
},
523523
}
524524

525525
result := graphql.Do(graphql.Params{
526526
Schema: schema,
527527
RequestString: query,
528528
})
529-
530-
if len(result.Errors) == 0 {
531-
t.Fatalf("wrong result, expected errors: %v, got: %v", len(expected.Errors), len(result.Errors))
532-
}
533-
if !reflect.DeepEqual(expected, result) {
529+
if !testutil.EqualResults(expected, result) {
534530
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
535531
}
536532
}
@@ -619,7 +615,6 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
619615
}
620616
}`
621617

622-
originalError := gqlerrors.NewFormattedError(`Runtime Object type "Human" is not a possible type for "Pet".`)
623618
expected := &graphql.Result{
624619
Data: map[string]interface{}{
625620
"pets": []interface{}{
@@ -635,8 +630,8 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
635630
},
636631
},
637632
Errors: []gqlerrors.FormattedError{
638-
gqlerrors.FormatError(gqlerrors.Error{
639-
Message: originalError.Message,
633+
{
634+
Message: `Runtime Object type "Human" is not a possible type for "Pet".`,
640635
Locations: []location.SourceLocation{
641636
{
642637
Line: 2,
@@ -647,19 +642,15 @@ func TestResolveTypeOnUnionYieldsUsefulError(t *testing.T) {
647642
"pets",
648643
2,
649644
},
650-
OriginalError: originalError,
651-
}),
645+
},
652646
},
653647
}
654648

655649
result := graphql.Do(graphql.Params{
656650
Schema: schema,
657651
RequestString: query,
658652
})
659-
if len(result.Errors) == 0 {
660-
t.Fatalf("wrong result, expected errors: %v, got: %v", len(expected.Errors), len(result.Errors))
661-
}
662-
if !reflect.DeepEqual(expected, result) {
653+
if !testutil.EqualResults(expected, result) {
663654
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
664655
}
665656
}

0 commit comments

Comments
 (0)