Skip to content

Commit 09272f3

Browse files
authored
Merge pull request #633 from graphql-go/union-types-test
definition: Adds `Union.Types` error handling unit test
2 parents a300a61 + bdd0ee3 commit 09272f3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

definition_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,25 @@ func TestTypeSystem_DefinitionExample_IncludesUnionTypesThunk(t *testing.T) {
706706
t.Fatalf("Unexpected result, someUnion should have two unionTypes, has %d", len(unionTypes))
707707
}
708708
}
709+
710+
func TestTypeSystem_DefinitionExample_HandlesInvalidUnionTypes(t *testing.T) {
711+
someUnion := graphql.NewUnion(graphql.UnionConfig{
712+
Name: "SomeUnion",
713+
Types: (graphql.InterfacesThunk)(func() []*graphql.Interface {
714+
return []*graphql.Interface{}
715+
}),
716+
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
717+
return nil
718+
},
719+
})
720+
721+
unionTypes := someUnion.Types()
722+
expected := "Unknown Union.Types type: graphql.InterfacesThunk"
723+
724+
if someUnion.Error().Error() != expected {
725+
t.Fatalf("Unexpected error, got: %v, want: %v", someUnion.Error().Error(), expected)
726+
}
727+
if unionTypes != nil {
728+
t.Fatalf("Unexpected result, got: %v, want: nil", unionTypes)
729+
}
730+
}

0 commit comments

Comments
 (0)