在 Node.js 中找不到解析 Apollo 标头

问题描述 投票:0回答:1

我在 React.js Web 应用程序中配置了以下标头,但在 Node.js API 中记录

req.headers
时我没有看到它们。
headerData.data
的值是在另一个文件中设置的,因此它不会传递空参数。

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()
});
reactjs node.js apollo
1个回答
0
投票

你需要做的稍微不同,你的嵌套是错误的:

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      "some-new-header": headerValue
    }
  }
})
© www.soinside.com 2019 - 2024. All rights reserved.