我在 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()
});
你需要做的稍微不同,你的嵌套是错误的:
const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
"some-new-header": headerValue
}
}
})