Unable to get apollo client response headers
See original GitHub issueI am able to see the response headers in the network but unable to get those response headers.
Please follow the below screenshots.
Network Response Headers:
Console Response Data(Empty headers):
Actual tried Code:
const httpLink = new HttpLink({ uri: URL_SERVER_GRAPHQL })
// Setup the header for the request
const middlewareAuthLink = new ApolloLink((operation, forward) => {
const token = localStorage.getItem(AUTH_TOKEN)
const authorizationHeader = token ? `Bearer ${token}` : null
operation.setContext({
headers: {
authorization: authorizationHeader
}
})
return forward(operation)
})
//After the backend responds, we take the refreshToken from headers if it exists, and save it in the cookie.
const afterwareLink = new ApolloLink((operation, forward) => {
return forward(operation).map(response => {
const context = operation.getContext()
const {
response: { headers }
} = context
if (headers) {
const refreshToken = headers.get('refreshToken')
if (refreshToken) {
localStorage.setItem(AUTH_TOKEN, refreshToken)
}
}
return response
})
})
const client = new ApolloClient({
link: from([middlewareAuthLink, afterwareLink, httpLink]),
cache: new InMemoryCache()
})
Please help with this issue.
Thanks in advance.
Issue Analytics
- State:
- Created 2 years ago
- Comments:21 (5 by maintainers)
Top Results From Across the Web
Advanced HTTP networking - Apollo GraphQL Docs
Apollo Client uses HttpLink to send GraphQL operations to a server over HTTP. The link supports both POST and GET requests, and it...
Read more >Apollo Link response headers - Stack Overflow
Does anybody know why the dev tool shows the headers object is empty?? If using CORS, you'll need to add your headers to...
Read more >Access Response Headers in Apollo Client - zach.codes
I have a server that sends back a new JWT with each response. There's a simple example on the Apollo docs of setting...
Read more >Unable to get apollo client response headers - Bountysource
I am able to see the response headers in the network but unable to get those response headers. Please follow the below screenshots....
Read more >ApolloClient link configuration - cannot see response headers
In my ApolloServer I am setting custom response headers that I need to be able to intercept on the client side.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @brainkim, Any update regarding this issue…?
Hi @brainkim, Any update regarding this issue…? let me know if anything is required.