【发布时间】:2020-09-11 00:18:01
【问题描述】:
我可以在客户端设置 cookie,但我不知道如何从服务器 reslover (apollo graphql.) 获取 cookie。
// 解析器.js
export const resolvers = {
Query: {
async getSinglePost(_, args, context) {
// "context.req.headers.cookies" are empty. d
// Even if setting "credentials: 'include' " in creating Apollo client chche.
},
},
// apolloClient.js
new ApolloClient({
ssrMode: Boolean(ctx),
link: authLink.concat(new HttpLink({
uri: 'http://localhost:4000/graphql', // Server URL (must be absolute)
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
fetch,
})),
cache: new InMemoryCache({ fragmentMatcher }).restore(initialState),
credentials: 'include',
})
我错过了什么吗?
【问题讨论】:
标签: graphql apollo apollo-client