Fixed subscription issue. Related to no authorization token for WS request.

This commit is contained in:
Patrick Fic
2019-12-11 23:17:09 -08:00
parent 3c3f1e8650
commit aa21c51023
3 changed files with 41 additions and 11 deletions

View File

@@ -30,7 +30,17 @@ class AppContainer extends Component {
const wsLink = new WebSocketLink({
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT_WS,
options: {
reconnect: true
reconnect: true,
connectionParams: () => {
const token = localStorage.getItem("token");
if (token) {
return {
headers: {
authorization: token ? `Bearer ${token}` : ""
}
};
}
}
}
});
@@ -38,7 +48,10 @@ class AppContainer extends Component {
// split based on operation type
({ query }) => {
const definition = getMainDefinition(query);
console.log("##Intercepted GQL Transaction##", query);
console.log(
"##Intercepted GQL Transaction##" + definition.operation,
query
);
return (
definition.kind === "OperationDefinition" &&
definition.operation === "subscription"
@@ -76,7 +89,8 @@ class AppContainer extends Component {
link: ApolloLink.from(middlewares),
cache,
typeDefs,
resolvers
resolvers,
connectToDevTools: true
});
client.writeData({