there is no information available on how to mount graphql union type on subscriptions. is it even possible?
type Subscription {
joinRequest(id: UUID!): MemberUnion!
}
type User { ... }
type Guest { ... }
union MemberUnion = User | Guest
and it's working perfectly with my queries or mutations, just need any information about how to implement with my subscription. joinRequest
key is userId
and role
. role
should stand for resolver where either user
or guest
information should be fetched by passed userId
argument.
error I see after trying to launch code as it is now:
"Abstract type "MemberUnion" must resolve to an Object type at runtime for field "Subscription.joinRequest" with value { userId: "3bdb0eb5-f237-40a7-bebc-6263cc18dba5", name: "trolololo3", payload: { ... } }, received "null". Either the "MemberUnion" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function."
my resolvers files which export queries, mutations and subscriptions:
import ....
export default {
Query: {
...User,
...Listing,
...Products
},
Mutation: {
...ListingMutations,
...ProductsMutations
},
Subscription: {
...ProductsSubscription,
...ListingSubscription
},
Products: {
items: ({ id: itemId }) => method({ itemId })
},
MemberUnion: {
// eslint-disable-next-line no-underscore-dangle
__resolveType: obj => {
if (obj.role === USER_ROLE.GUEST) {
return 'Guest';
}
if (obj.role === USER_ROLE.USER) {
return 'User';
}
return null;
}
},
....
and as I said before, this works fine when I implement MemberUnion
on any query or mutation response where I want to select user object which could be user or guest.