Fixed subscription issue. Related to no authorization token for WS request.
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user