Given a unique GraphQL union
return type:
union GetUserProfileOrDatabaseInfo = UserProfile | DatabaseInfo
meant to be returned by a specific resolver:
type Query {
getUserData: GetUserProfileOrDatabaseInfo!
}
I am encountering warnings and errors related to the __resolveType
or __isTypeOf
function:
The abstract type M must resolve to an Object type at runtime for field Query.getUserData with value { ..., __isTypeOf: [function __isTypeOf] }, received "undefined". Either the M type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.'
After extensive research on GitHub issues and Stack Overflow questions, I have yet to find a solution to fix this error.
Implementing __resolveType
or __isTypeOf
in my resolvers has been unsuccessful:
export const Query = {
getUserData: (parent, args, context: IContext, info) => {
return {
__isTypeOf(obj) { // OR __resolveType, none of them work
return `UserProfile`;
},
data: []
};
},
};