Apollo-client: empty headers object in afterware response

Created on 17 Sep 2017  路  6Comments  路  Source: apollographql/apollo-client

Hi,

I have a similar issue to #1156. But in my case the response is completely empty.
Here is my afterware:

apolloClient.networkInterface.useAfter([{
    applyAfterware({ response }, next) {
        if (process.env.NODE_ENV === 'development') {
            console.log('got new response', response);
        }
        next();
    }
}]);

Here is the real response:
response screenshot

Here is the console log:
console log screenshot

BTW. I've already asked at StackOverflow

Most helpful comment

Additional comment here, the headers object in Chrome is actually of the type Headers. To get the values you actually need to do response.headers.get(key) . This fixed the issue for me

All 6 comments

is there anybody out there?

I am also having this issue, headers are completely empty.

@Artem-Schander did you create any headers on the initial request? This should be fixed by using apollo-link with the 2.0. Here is an upgrade guide if you are interested in the migration to links https://github.com/apollographql/apollo-client/blob/master/Upgrade.md#upgrading-from-custom-networkinteface-with-middleware--afterware

Additional comment here, the headers object in Chrome is actually of the type Headers. To get the values you actually need to do response.headers.get(key) . This fixed the issue for me

Thanks to both of you, but update the apollo-client to v2 is in my case not an option. I'm using vue-apollo so the dependency is ^1.0

To receive headers, you need to expose them first on the server-side. You can read more on Access-Control-Expose-Headers. If you're using cors, you may use:

app.use(cors({
  exposedHeaders: 'custom-header'
}));

I've found this information in this issue: https://github.com/apollographql/apollo-client/issues/1156

Was this page helpful?
0 / 5 - 0 ratings