In React Apollo client, we have some links configured.
const apollo = new ApolloClient({
cache: new InMemoryCache(),
link: from([
onErrorLink,
afterwareLink,
httpLink
])
});
In our application, when session times out we return the response with 200
status and some response headers (timeout: true
). By using these response headers we need to show some dialog on UI. The response header also has content-type: text/html
. Also remember, sessions
are maintained on federal level (SSO) in our organization and we do not control response context for that.
When session times out and we receive response from server, Apollo react client onError
link fires up and we try to access response as below.
const context = operation.getContext();
const response = context.response;
const headers = response.headers;
In above code, context
never has response
property and hence response
is undefined
. Due to this, I am not able to access header values.
Analysis
const afterwareLink = new ApolloLink((operation, forward) => {
return forward(operation).map(response => {
const context = operation.getContext();
const response = context.response;
const headers = response.headers;
return response;
})
};
- I have seen in case of error, only
onError
is resolved andafterwareLink
map function never triggers. response
is populated incontext
only if comes viaforward
function given by Apollo.- In successful API calls,
afterwareLink
map function do resolves and I am able to find all headers just fine. - Solutions online are similar but just does not work.
I am stumped here. I can clearly see response headers in Dev Tools and Fiddler. It's for sure there. Just Apollo is not allowing me to access that. In my case, networkError
or graphQLErrors
are not of much use.