我尝试按照 Apollo 客户端上的说明与 graphql 请求一起发送 cookie,但是 Express 服务器没有收到任何 cookie,并且当我检查请求时,它显示没有随响应一起发送 cookie。
关注此页面:
https://www.apollographql.com/docs/react/recipes/authentication.html
我的代码是
const link = createHttpLink({
uri: 'http://localhost:3000/api/graphql',
opts: {
credentials: 'include',
}
});
const client = new ApolloClient({
link,
cache: new InMemoryCache()
});
我的设置非常简单,我只是在 localhost:3000 上使用 create-react-app 服务器,将 api 请求发送到 localhost:5000 (express api 服务器)。我可以在其他路由上通过 localhost:3000 设置和检索 cookie,只有 Apollo 客户端不发送它们。
我不明白为什么文档会说明它的作用,尽管具有更多经验的开发人员可能不会遇到问题。
无论如何,经验不足的开发人员应该注意的是:
const link = createHttpLink({
uri: 'http://localhost:3000/api/graphql',
opts: {
credentials: 'include',
}
});
它应该只是:
const httpLink = createHttpLink({
uri: 'http://localhost:3000/api/graphql',
credentials: 'same-origin'
});
换句话说,没有单独的opts
createHttpLink 配置对象中的对象。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)