I've done a good bit of research on using pubsub in the SubscriptionServer onConnect and onDisconnect methods and haven't found any ways to do this or work arounds. I'm wanting to publish events to other clients when subscriptions open/close with a specific client.
Example of what I would like to be able to do
const subscriptionServer = SubscriptionServer.create({
schema,
context: authMiddleware,
execute,
subscribe,
onConnect(connectionParams) {
const token = connectionParams.authToken.split(' ').pop().trim();
if(token){
try {
const { data } = jwt.verify(token, secret, { maxAge: expiration });
console.log(`${data.username} has connected`);
// I would like to publish this event to the subscriptions in my resolvers
pubsub.publish('USER_CONNECTED', {/* data to be passed */});
return data
} catch {
console.log('Invalid token');
}
}
return false;
},
onDisconnect(_,context){
context.initPromise.then( async user=>{
if(user){
console.log(`${user.username} has disconnected`)
// I would like to publish this event to the subscriptions in my resolvers
pubsub.publish('USER_DISCONNECTED', {/* data to be passed */});
}
})
}
}, {
server: httpServer,
path: server.graphqlPath
});
I've done a good bit of research on using pubsub in the SubscriptionServer onConnect and onDisconnect methods and haven't found any ways to do this or work arounds. I'm wanting to publish events to other clients when subscriptions open/close with a specific client.
Example of what I would like to be able to do
My resolvers look like: