WebSocket object in subscriptions

prisma

#1

Good day!

When prisma server inited, in context pass request object https://github.com/graphcool/prisma/blob/master/examples/subscriptions/src/index.js#L47
In query/mutation resolvers this object is accessible via ctx…
But in subscription resolver not.

subscribeUsersOnline = {
  subscribe: async (source, args, ctx, info) => {
      // nead here
  },
}

How can i got it?

Thanks!

UPD: in main requests passed { request, response } https://github.com/graphcool/graphql-yoga/blob/master/src/index.ts#L223
In subscription only connection params https://github.com/graphcool/graphql-yoga/blob/master/src/index.ts#L308
Why these differences?


#2

Hey there,

Subscription’s context are available through ctx.connection.context instead of ctx.request.

I don’t know for sure the reasons behind this, but it has to do with queries/mutations being HTTP requests, and subcriptions being websocket requests.

There is an open issue at the moment to figure out how to do authenticated subscription: https://github.com/prismagraphql/graphql-yoga/issues/343.

Note: The context is properly passed when instantiating your websocket apollo-client with { connectionParams: {...} }.