swapi-graphql icon indicating copy to clipboard operation
swapi-graphql copied to clipboard

CORS Issue

Open Lishenga opened this issue 4 years ago • 13 comments

Hello am getting this error when trying to get an introspection of your graphql api using graphql voyager

Access to fetch at 'https://graphql.org/swapi-graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Could you kindly assist me or tell me why am getting this error?

Lishenga avatar Nov 07 '20 07:11 Lishenga

try using this fetch option:

credentials: 'omit'

here's en example: https://github.com/graphql/graphiql/blob/6ca519a9f0b0b9c55e77f8b4a73320036cba5652/packages/graphiql/resources/renderExample.js#L119

acao avatar Nov 20 '20 15:11 acao

@Lishenga you may need to open an issue in graphql voyager

acao avatar Nov 20 '20 15:11 acao

I am getting this issue too. Any idea how to fix this issue ?

nishanthsinghgurung2 avatar Feb 08 '21 14:02 nishanthsinghgurung2

Hello, I am also getting the similar CORS issue when trying to use swapi-graphql with the v3 Apollo client in react: https://www.apollographql.com/docs/react/get-started/#create-a-client

My Apollo client configuration is as follows:

const client = new ApolloClient({
  uri: "https://graphql.org/swapi-graphql",
  cache: new InMemoryCache(),
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "DELETE, POST, GET, OPTIONS",
    "Access-Control-Allow-Headers":
      "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
  },
  credentials: "omit",
});

As seen I had tried setting the headers and credentials property but still getting the same error. Please let me know if there is anything else I can try.

chackop avatar Feb 13 '21 02:02 chackop

i'm getting the same issue. Any help please? Sounds like the API needs to allow * access, otherwise introduce API keys?

ttbarnes avatar Feb 16 '21 10:02 ttbarnes

Any updates on this? I'm also getting the same error.

kiliw avatar Apr 05 '21 17:04 kiliw

Chiming in to ask if there is any update on this issue? Still getting the same error when trying to access the API. Thanks!!

liztownd avatar Jun 09 '21 01:06 liztownd

Same issue

edit: here's an alternative endpoint that seems to work https://swapi-graphql.netlify.app/.netlify/functions/index

SupeDeDupe avatar Aug 16 '21 15:08 SupeDeDupe

Same issue here

o-az avatar Sep 04 '21 04:09 o-az

I'm having the same problem. Has anyone been able to come across a solution?

JoshuaFurman avatar Sep 11 '21 14:09 JoshuaFurman

I'm having the same problem. Has anyone been able to come across a solution?

@JoshuaFurman use this alternative endpoint:

https://swapi-graphql.netlify.app/.netlify/functions/index

o-az avatar Sep 11 '21 23:09 o-az

Hello, I am also getting the similar CORS issue when trying to use swapi-graphql with the v3 Apollo client in react: https://www.apollographql.com/docs/react/get-started/#create-a-client

My Apollo client configuration is as follows:

const client = new ApolloClient({
  uri: "https://graphql.org/swapi-graphql",
  cache: new InMemoryCache(),
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "DELETE, POST, GET, OPTIONS",
    "Access-Control-Allow-Headers":
      "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
  },
  credentials: "omit",
});

As seen I had tried setting the headers and credentials property but still getting the same error. Please let me know if there is anything else I can try.

Replace your URI with this and it will work: https://swapi-graphql.netlify.app/.netlify/functions/index

NOTE: remove the headers object as they are not needed anymore.

Deevoid avatar Jan 23 '22 08:01 Deevoid

I think we need to change the graphql netlify _redirects to proxy the old path?

acao avatar Feb 08 '22 17:02 acao