Apollo headers not found parsing in Node.js

31 views Asked by At

I have the following header configured in my React.js web app, but I don't see them when logging req.headers in my Node.js API. The value of headerData.data is set in another file, so it's not passing a null parameter.

export const headerData = {
  data: null
};

const httpLink = createHttpLink({
  uri: 'http://localhost:4300/graphql'
})

const authLink = setContext((_, { headers }) => {
  return {
    ...headers,
    headerData: headerData.data
  }
})

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
});
1

There are 1 answers

0
phry On

You need to do it slightly different, your nesting is wrong:

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      "some-new-header": headerValue
    }
  }
})