I am using the latest version of Apollo Client in a simple React app and I am trying to pull out a header value from the response that is being used to show the size of the record set being returned.
I appreciate that this is not the most elegant way of providing the result set size, but that is how the API has currently been set up.
I was hoping to use the the middleware type options to do this, but when I inspect the response object I can't seem to pull out any headers.
The network trace does show that the response header is as expected so I suspect I am misunderstanding how to get at the underlying objects that I need.
I have checked the documentation, but nothing stands out as obvious hence the question here ...
Found the answer here: https://github.com/apollographql/apollo-client/issues/2514
Have to access it via the operation context ... interestingly the dev tools appears to show that the headers object is empty, but you can then pull named headers from it ...
When the backend responds, the headers should include:
Access-Control-Expose-Headers: *
// or the name of your refreshToken fieldHere you have the full code:
Front End: (Apollo & React)
In the backend (express). If we need to refresh the token (e.g: because the actual one is going to expire)
Documentation from: https://www.apollographql.com/docs/react/networking/network-layer/#afterware