Urigo/graphql-modules

Subscription middleware contains only injector

daytona63 opened this issue · 1 comments

Describe the bug

Cant get anything but injector in middleware when applied to subscription

To Reproduce
1 - Clone the codebase
2 - install packages
3 - run npm dev
4 - open playground
5 - subscribe to this

subscription _empty {
  _empty {
    id
    message
  }
}

https://github.com/rolexAk/gql-modules

Expected behavior

I expect it to show request header to get cookies and check if the person listening is authenticated or not

Environment:

  • OS: MAC M1 PRO
  • @graphql-modules/...: "^2.1.0"
  • NodeJS: 18.12.0

Additional context

I can simply add the middleware to the ws server but i dont want ever subscription to be authenticated

Nvm, figured it out

Here was the solution

had to pass the values in context on the graphql-ws useServer

  context: async (ctx) => {
        const { extra } = ctx;

        const req = extra.request;
      
        (req as unknown as IRequest).cookies = cookie.parse(extra.request.headers.cookie || '');

        return {
          ...ctx,
          req,
        };
      },