Laravel Lighthouse sending OPTIONS request with every mutation, how to stop it?

418 Views Asked by At

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:

CORS OPTIONS 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,
1

There are 1 best solutions below

0
On BEST ANSWER

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.