forked from statamic/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheResponse.php
More file actions
39 lines (28 loc) · 795 Bytes
/
Copy pathCacheResponse.php
File metadata and controls
39 lines (28 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Statamic\GraphQL\Middleware;
use Closure;
use Statamic\Contracts\GraphQL\ResponseCache;
class CacheResponse
{
public function handle($request, Closure $next)
{
if ($request->statamicToken()) {
return $next($request);
}
if ($this->isMutation($request)) {
return $next($request);
}
$cache = app(ResponseCache::class);
if ($response = $cache->get($request)) {
return $response;
}
$response = $next($request);
$cache->put($request, $response);
return $response;
}
protected function isMutation($request): bool
{
$query = ltrim(strtolower($request->get('query', '')));
return str_starts_with($query, 'mutation');
}
}