Skip to content

Commit

Permalink
fix tests to account for runtime checking of interface implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
  • Loading branch information
sipsma committed Dec 12, 2023
1 parent 0da6393 commit 01b09ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions abstract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
humanType = graphql.NewObject(graphql.ObjectConfig{
Name: "Human",
Fields: graphql.Fields{
"name": &graphql.Field{
"job": &graphql.Field{
Type: graphql.String,
},
},
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestResolveTypeOnInterfaceYieldsUsefulError(t *testing.T) {
},
Errors: []gqlerrors.FormattedError{
{
Message: `Runtime Object type "Human" is not a possible type for "Pet".`,
Message: `"Pet" expects field "name" but "Human" does not provide it.`,
Locations: []location.SourceLocation{
{
Line: 2,
Expand Down
6 changes: 6 additions & 0 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,12 @@ func completeAbstractValue(eCtx *executionContext, returnType Abstract, fieldAST
}
if unionReturnType, ok := returnType.(*Union); ok && unionReturnType.ResolveType != nil {
runtimeType = unionReturnType.ResolveType(resolveTypeParams)
if !eCtx.Schema.IsPossibleType(returnType, runtimeType) {
panic(gqlerrors.NewFormattedError(
fmt.Sprintf(`Runtime Object type "%v" is not a possible type `+
`for "%v".`, runtimeType, returnType),
))
}
} else if interfaceReturnType, ok := returnType.(*Interface); ok && interfaceReturnType.ResolveType != nil {
runtimeType = interfaceReturnType.ResolveType(resolveTypeParams)
// verify the object matches the interface
Expand Down

0 comments on commit 01b09ff

Please sign in to comment.