Ex.
const clientRef = useRef(initClient());
function initClient() {
const authLink = setContext(async (_, options) => {
const {
headers = {
'Accept-Language': 'en',
},
} = options;
headers.Authorization = `Bearer ${token}`;
return {
headers,
};
});
const client = new ApolloClient({
link: ${url},
cache: new InMemoryCache(),
defaultOptions,
});
return client;
}
here is my configuration and here is my query and mutation.
const handleQuery = async (params) => {
const res = await clientRef.current.query(params);
const { data, errors } = res;
if (errors) {
checkErrorForUnauthenticated(errors);
}
return { data };
};
const handleMutation = async (params) => {
const res = await clientRef.current.mutate(params);
const { data, errors } = res;
if (errors) {
checkErrorForUnauthenticated(errors);
}
return { data };
};
Problem:-
I have 3 apis on HOC and 5 apis in child component. so when access token expire after 1 API call. I have to call another endpoint to get access token and then want to call remain apis. but now problem is while doing call for refresh token other apis are fired with old token and got error.