pllumh
12/25/2018, 10:11 PMheaders
or connectionParams
in subscriptions in graphql bindings... My code in Apollo:
wsLink.subscriptionClient.use([{
async applyMiddleware(options, next) {
// get the authentication token from local storage if it exists
const token = cookie.load('access_token');
options.connectionParams = {
authorization: token ? `Bearer ${token}` : "",
};
next();
},
}]);
const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
const token = cookie.load('access_token');
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
}
}
});