diff --git a/config/graphql.php b/config/graphql.php index 132e71f355..02f8258ce3 100644 --- a/config/graphql.php +++ b/config/graphql.php @@ -42,6 +42,20 @@ // ], + /* + |-------------------------------------------------------------------------- + | Mutations + |-------------------------------------------------------------------------- + | + | Here you may list mutations to be added to the Statamic schema. + | + | https://statamic.dev/graphql#custom-mutations + */ + + 'mutations' => [ + // + ], + /* |-------------------------------------------------------------------------- | Middleware diff --git a/src/GraphQL/DefaultSchema.php b/src/GraphQL/DefaultSchema.php index 6cde23ac0e..1aaed9f1a1 100644 --- a/src/GraphQL/DefaultSchema.php +++ b/src/GraphQL/DefaultSchema.php @@ -45,7 +45,7 @@ public function getConfig() { return [ 'query' => $this->getQueries(), - 'mutation' => [], + 'mutation' => $this->getMutations(), 'middleware' => $this->getMiddleware(), 'method' => ['GET', 'POST'], ]; @@ -82,4 +82,9 @@ private function getMiddleware() GraphQL::getExtraMiddleware() ); } + + private function getMutations() + { + return config('statamic.graphql.mutations', []); + } } diff --git a/src/GraphQL/Middleware/CacheResponse.php b/src/GraphQL/Middleware/CacheResponse.php index 45b6360f5a..73b5b14636 100644 --- a/src/GraphQL/Middleware/CacheResponse.php +++ b/src/GraphQL/Middleware/CacheResponse.php @@ -13,6 +13,10 @@ public function handle($request, Closure $next) return $next($request); } + if ($this->isMutation($request)) { + return $next($request); + } + $cache = app(ResponseCache::class); if ($response = $cache->get($request)) { @@ -25,4 +29,11 @@ public function handle($request, Closure $next) return $response; } + + protected function isMutation($request): bool + { + $query = ltrim(strtolower($request->get('query', ''))); + + return str_starts_with($query, 'mutation'); + } }