I'm trying to use NestJS subscriptions, I have tried both graphql-ws
and subscriptions-transport-ws
.
I have a very basic use case -- an interceptor to take the authorization header and then set the user object on the connection or request object to be able to use by the resolvers.
I've looked through the docs and several other SO posts but none of the solutions worked.
Current syntax:
const ctx = GqlExecutionContext.create(context).switchToWs().getClient(); // undefined
const ctx = GqlExecutionContext.create(context).getContext(); // undefined
In the module subscriptions config, I can see the auth header being passed for the subscriptions-transport-ws
block of code and the `graphql-ws- block of code.
But in the interceptor everything returned is undefined.
subscriptions: {
'graphql-ws': {
path: '/apis/event-service/graphql',
onConnect: (ctx) => {
console.log('CONTEXT', ctx);
},
},
'subscriptions-transport-ws': {
path: '/apis/event-service/graphql',
onConnect: (ctx) => {
console.log('CONTEXT', ctx);
},
},
},
How do I get the context?