apollographql/apollo-link

Websocket credentials

Opened this issue · 0 comments

In order to add credentials to HTTP requests, I use the following code segment.

const authLayer = new ApolloLink((operation, forward) => {
    operation.setContext({
      headers: {
        authorization: session
      }
    })
    return forward(operation)
  })

The benefit of this is, that session can be changed at runtime and always carries the most up-to-date value. In contrast, the websocket link requires me to specify the credentials at creation time. Like so.

const wsLink = new WebSocketLink({
    uri: `${window.location.origin.replace('http', 'ws')}/graphql`,
    options: {
      reconnect: true,
      connectionParams: {
        authorization: session
      }
    }
  })

If my session changes, I will have to create a new websocket link instance. Is there a way around this?