I am using Astro and Apollo Client.
I need to set a custom Response Header.
How to set a custom response header when doing a GraphQL request?
In my Apollo Client file:
const myCustomHeaderLink = new ApolloLink((operation, forward) => {
return forward(operation).map((result) => {
res.headers.set('My-Custom-Header', 'my-value'); // How to get access to the `response` here?
return result;
});
});
export const client = new ApolloClient({
cache: new InMemoryCache(),
ssrMode: true,
link: from([myCustomHeaderLink, httpLink]),
});
On the client you
seta request header andgeta response header. Assuming you are trying to do the former then you'll want to usesetContextin a custom link:Then add this link to your link chain.