Access to fetch at 'https://mydomain.io/dev/functions/graphql' from origin 'https://www.mydomain.io' 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.
So, I need to add to the graphql Function response headers:
If CORS is enabled per apollo-server-lambda’s instructions I confirmed that I did get the response headers … I just inspected http://localhost:8911/graphql for a quick check.
That’s great, thank you a lot! I solved it moving everything into the same domain (API and web), but it’s a great improvement because having the API and the web in different subdomains adds a lot of flexibility. Thanks!
I’m having similar issue, with api deployed on a different domain and a cors issue, I’ve added the settings to the handler as @dthyresson had suggested but am still getting the error but only for the currenty user query. I have a dev endpoint up still so this should be able to replicate.
This request has a response with access-control-allow-origin: * :
Since the query redwood { currentUser }} is not part of the user defined graphql schema, could something funny/unique be happing with this particular query.
For reference this is branch I’ve deployed the above from using yarn rw deploy aws serverless
were you able to figure to solve this? I am running into the same problem.
The query __REDWOOD__AUTH_GET_CURRENT_USER is blocked by CORS when deploying to an AWS Lambda.
The payload is {"query":"query __REDWOOD__AUTH_GET_CURRENT_USER { redwood { currentUser } }"}
My handler looks like this:
export const handler = createGraphQLHandler({
loggerConfig: { logger, options: {} },
getCurrentUser,
directives,
sdls,
services,
cors: {
origin: '*',
credentials: true,
},
onException: () => {
// Disconnect from your database with an unhandled exception.
db.$disconnect()
},
})
Hey @danny, thanks for making me aware of this conversation. I tried to set origin in graphql.ts but it did not solve the problem. I do not have the time to investigate in the moment. I will put it on my to-do list and comment here, when I was able to set up an environment for reproduction.