question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to get apollo client response headers

See original GitHub issue

I 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: Screenshot from 2021-03-24 16-12-17

Console Response Data(Empty headers): Screenshot from 2021-03-24 16-14-19

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:closed
  • Created 2 years ago
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
Suribabu-Balamcommented, May 17, 2021

Hi @brainkim, Any update regarding this issue…?

2reactions
Suribabu-Balamcommented, Apr 26, 2021

Hi @brainkim, Any update regarding this issue…? let me know if anything is required.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found