如何从apollo graphql解析器获取cookie?

如何从apollo graphql解析器获取cookie?,graphql,apollo,apollo-client,Graphql,Apollo,Apollo Client,我可以在客户端设置cookie,但我不知道如何从服务器reslover(apollo graphql)获取cookie //resolver.js export const resolvers = { Query: { async getSinglePost(_, args, context) { // "context.req.headers.cookies" are empty. d // Even if setting "credentials

我可以在客户端设置cookie,但我不知道如何从服务器reslover(apollo graphql)获取cookie

//resolver.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',
  })

我错过了什么吗?

我认为这与Apollo服务器本身无关,因为假设您使用express,
req
对象直接传递到上下文中,Apollo根本不会修改它

相反,我会检查,如果你甚至分析饼干。为此,建议将其作为中间件使用和运行


此外,cookie对象应该位于
req.cookies
中(而不是
req.headers.cookies

cookieParser
中间件已经设置好了。。。我错过了一些东西。。。我不知道它是什么。我的graphql服务器在端口
4000
上运行,我的nextjs客户端在端口
3000
上运行。我可以使用express router获取客户端cookie,但无法在graphql解析器中获取。Apollo似乎有问题:@Juntae找到了解决方法吗?我从
apollo server
切换到
apollo server express
,并使用cookie解析器中间件配置了自己的express实例。直到那时它才起作用。我现在可以使用
context.req.cookies