2
2
3
3
namespace Drupal \graphql \GraphQL \Execution ;
4
4
5
+ use Drupal \Component \Datetime \TimeInterface ;
5
6
use Drupal \Core \Cache \Cache ;
6
7
use Drupal \Core \Cache \CacheableMetadata ;
7
8
use Drupal \Core \Cache \CacheBackendInterface ;
22
23
use GraphQL \Utils \AST ;
23
24
use Symfony \Component \DependencyInjection \ContainerInterface ;
24
25
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
25
- use Symfony \Component \HttpFoundation \RequestStack ;
26
26
27
27
/**
28
28
* Executes GraphQL queries with cache lookup.
@@ -51,11 +51,9 @@ class Executor implements ExecutorImplementation {
51
51
protected $ contextsManager ;
52
52
53
53
/**
54
- * The request stack.
55
- *
56
- * @var \Symfony\Component\HttpFoundation\RequestStack
54
+ * The date/time service.
57
55
*/
58
- protected $ requestStack ;
56
+ protected TimeInterface $ time ;
59
57
60
58
/**
61
59
* The event dispatcher.
@@ -127,8 +125,8 @@ class Executor implements ExecutorImplementation {
127
125
* The cache contexts manager service.
128
126
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
129
127
* The cache backend for caching query results.
130
- * @param \Symfony \Component\HttpFoundation\RequestStack $requestStack
131
- * The request stack .
128
+ * @param \Drupal \Component\Datetime\TimeInterface $time
129
+ * The date/time service .
132
130
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
133
131
* The event dispatcher.
134
132
* @param \GraphQL\Executor\Promise\PromiseAdapter $adapter
@@ -143,7 +141,7 @@ class Executor implements ExecutorImplementation {
143
141
public function __construct (
144
142
CacheContextsManager $ contextsManager ,
145
143
CacheBackendInterface $ cacheBackend ,
146
- RequestStack $ requestStack ,
144
+ TimeInterface $ time ,
147
145
EventDispatcherInterface $ dispatcher ,
148
146
PromiseAdapter $ adapter ,
149
147
Schema $ schema ,
@@ -156,7 +154,7 @@ public function __construct(
156
154
) {
157
155
$ this ->contextsManager = $ contextsManager ;
158
156
$ this ->cacheBackend = $ cacheBackend ;
159
- $ this ->requestStack = $ requestStack ;
157
+ $ this ->time = $ time ;
160
158
$ this ->dispatcher = $ dispatcher ;
161
159
162
160
$ this ->adapter = $ adapter ;
@@ -198,7 +196,7 @@ public static function create(
198
196
return new static (
199
197
$ container ->get ('cache_contexts_manager ' ),
200
198
$ container ->get ('cache.graphql.results ' ),
201
- $ container ->get ('request_stack ' ),
199
+ $ container ->get ('datetime.time ' ),
202
200
$ container ->get ('event_dispatcher ' ),
203
201
$ adapter ,
204
202
$ schema ,
@@ -444,8 +442,7 @@ protected function cacheWrite($prefix, CacheableExecutionResult $result) {
444
442
* @see \Drupal\Core\Cache\CacheBackendInterface::set()
445
443
*/
446
444
protected function maxAgeToExpire ($ maxAge ) {
447
- // @todo Can be removed when D9 support is dropped.
448
- $ time = $ this ->requestStack ->getMainRequest ()->server ->get ('REQUEST_TIME ' );
445
+ $ time = $ this ->time ->getRequestTime ();
449
446
return ($ maxAge === Cache::PERMANENT ) ? Cache::PERMANENT : (int ) $ time + $ maxAge ;
450
447
}
451
448
0 commit comments