4

我遵循了Github Codespace中的 Apollo Getting Started示例。

启动服务器后,我看到错误:

{
  "error": "Preflight response is not successful"
}

要重现的示例 repo 在这里:https ://github.com/aniskny/codespaces-test

我尝试了各种选项,cors但没有奏效:

...
new ApolloServer({ typeDefs, resolvers
  cors: {
    "origin": "*",
    "methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
    "preflightContinue": false,
    "optionsSuccessStatus": 204
  }
});
...
4

1 回答 1

3

我有同样的问题。事实证明,Playground 没有转发您的 Github 凭据。请注意,如果您在隐身窗口中访问预览 URL,您将被重定向到 Github 登录屏幕。解决方案是更改 Playground 设置,以便在 GraphQL 请求中发送您的凭据。

  1. 点击右上角,点击齿轮图标(设置)
  2. 更改以下内容
-  "request.credentials": "omit",
+  "request.credentials": "same-origin",
于 2020-10-30T02:25:20.750 回答