I'm getting CORS issues when trying to call the server from apollo client running in a web page. The server was setup using this example: https://github.com/maxdarque/up-graphql-yoga-server-example
Failed to load https://10t6y41fnc.execute-api.us-east-1.amazonaws.com/development: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 500. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
See issue here for more details: https://github.com/maxdarque/up-graphql-yoga-server-example/issues/3
It seems to me to be a graphql-yoga i.e. express causing this vs AWS gateway but I'm not 100% sure. I tried setting the middleware like in this article: https://blog.graph.cool/enabling-cors-for-express-graphql-apollo-server-1ef999bfb38d
except I did this to work with the GraphQLServer (src/index.ts):
const options = {
port: 4000,
cors: {
origin: "*"
}
};
server.start( options,({ port }) => console.log(Server is running on http://localhost:${ port }));
Didn't work for me either.
FYI: I can run everything correctly in the playground :/
Solution here for those who are interested: https://github.com/maxdarque/up-graphql-yoga-server-example/issues/3
@abelovic can you quickly summarize the solution here in a comment?
Most helpful comment
@abelovic can you quickly summarize the solution here in a comment?