使用 apollo 服务器 lambda 时,我得到 {"statusCode":400,"error":"Bad Request","message":"Invalid cookie value"}

When using apollo server lambda I am getting {"statusCode":400,"error":"Bad Request","message":"Invalid cookie value"}

我已经正确设置了这里是我的服务器的样子:

  return apolloServer.createHandler({
    expressGetMiddlewareOptions: {
      cors: {
        origin: ['http://localhost:8080', 'https://studio.apollographql.com'],
        credentials: true,
      },
    }
  })(event, context, callback)

这就是我通过将 sameSite 设置为 none 并将安全设置为 true

来定义 cookie 的方式
    setCookies.push({
      name: "cookieName",
      value: "cookieContent",
      options: {
        // expires: moment().add(1, 'hours').format(),
        httpOnly: true,
        maxAge: 3600,
        path: "/",
        sameSite: 'none',
        secure: true
      }
    });

我还启用了在工作室中发送 cookie。因此,当我向 studio apollo graphql 发出请求时,事情会按预期工作,我拥有的仅 http cookie 正在保存到 chrome.

这里是完整的 http 请求

accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 1523
content-type: application/json
Cookie: g_state={"i_l":0}; cookieName=cookieContent
Host: localhost:3000
Origin: http://localhost:8080
Referer: http://localhost:8080/
sec-ch-ua: "Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36

出于某种原因,在 apollo 客户端中我收到了这样的回复:

{"statusCode":400,"error":"Bad Request","message":"Invalid cookie value"}

在客户端,这是我所拥有的:

const link = new HttpLink({
  uri: process.env.REACT_APP_GRAPH_QL_URI,
  credentials: 'include'
});
const client = new ApolloClient({
  cache,
  link
});

经过几个小时的谷歌搜索,我很困惑为什么我会在客户端收到此错误,但工作室网站的一切都按预期工作。

我最终发现它是无服务器离线包,有一个标志 --disableCookieValidation 我猜它为包 hapi 设置了一些选项,这将解决我回来的验证问题。