I'm using Laravel with Lighthouse-PHP graphql, everything working fine, but the graph sends cors OPTIONS request every time I send mutations.
- Here's the mutation request:
I configured config/cors.php
as following, but still the same:
'paths' => ['api/*', 'graphql', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
- API on: http://127.0.0.1:8000/
- Frontend (Next JS & Apollo Client) on: http://localhost:7777/
A CORS request requires a pre-flight request which is the OPTIONS request you are seeing.
You can instruct the browser to cache the result by setting
max_age
in the CORS config to a non-0 value.It’s in seconds so you could set it to 300 to cache the result for 5 minutes which would result in the OPTIONS request only occurring once every 5 minutes.