"Preflight response is not successful" in Apollo Server running on GitHub Codespaces

601 views Asked by At

I followed the Apollo Getting Started example in a Github Codespace.

Upon starting the server, I see the error:

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

Sample repo to reproduce is here: https://github.com/anishkny/codespaces-test

I tried various options for cors but it did not work:

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

There are 1 answers

1
charltoons On

I had this same issue. It turns out that Playground is not forwarding your Github credentials. Notice that if you visit the preview URL in an incognito window, you are redirected to the Github login screen. The solution is to change Playground settings so that your credentials are sent in GraphQL requests.

  1. Click the top right corner, click the gear icon (settings)
  2. Change the following
-  "request.credentials": "omit",
+  "request.credentials": "same-origin",