I am trying to send a common variable with every request through react-apollo. So I tried with ApolloLink to add variable in the operation, but while inspecting the network I can't see the variable going with the query.
Here's how I have written the middleware:
const authLink2 = new ApolloLink((operation, forward) => {
operation.variables['entityId'] = '633'// localStorage.getItem('entityId');
operation.setContext(({ headers }) => {
const token = localStorage.getItem(AUTH_TOKEN);
return {
headers: {
...headers,
Authorization: token ? `JWT ${token}` : "",
}
}
});
// until this log I can see the entityId variable has been appended
console.log('operation', operation);
return forward(operation);
});
// creating ApolloClient
export const client = new ApolloClient({
link: authLink2.concat(httpLink),
cache
});
If this is not possible with ApolloLink middlware, please help me find a way to append the variable with every request.