22
33namespace Drupal \graphql \GraphQL \Execution ;
44
5+ use Drupal \Component \Datetime \TimeInterface ;
56use Drupal \Core \Cache \Cache ;
67use Drupal \Core \Cache \CacheableMetadata ;
78use Drupal \Core \Cache \CacheBackendInterface ;
2223use GraphQL \Utils \AST ;
2324use Symfony \Component \DependencyInjection \ContainerInterface ;
2425use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
25- use Symfony \Component \HttpFoundation \RequestStack ;
2626
2727/**
2828 * Executes GraphQL queries with cache lookup.
@@ -51,11 +51,9 @@ class Executor implements ExecutorImplementation {
5151 protected $ contextsManager ;
5252
5353 /**
54- * The request stack.
55- *
56- * @var \Symfony\Component\HttpFoundation\RequestStack
54+ * The date/time service.
5755 */
58- protected $ requestStack ;
56+ protected TimeInterface $ time ;
5957
6058 /**
6159 * The event dispatcher.
@@ -127,8 +125,8 @@ class Executor implements ExecutorImplementation {
127125 * The cache contexts manager service.
128126 * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
129127 * 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 .
132130 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
133131 * The event dispatcher.
134132 * @param \GraphQL\Executor\Promise\PromiseAdapter $adapter
@@ -143,7 +141,7 @@ class Executor implements ExecutorImplementation {
143141 public function __construct (
144142 CacheContextsManager $ contextsManager ,
145143 CacheBackendInterface $ cacheBackend ,
146- RequestStack $ requestStack ,
144+ TimeInterface $ time ,
147145 EventDispatcherInterface $ dispatcher ,
148146 PromiseAdapter $ adapter ,
149147 Schema $ schema ,
@@ -156,7 +154,7 @@ public function __construct(
156154 ) {
157155 $ this ->contextsManager = $ contextsManager ;
158156 $ this ->cacheBackend = $ cacheBackend ;
159- $ this ->requestStack = $ requestStack ;
157+ $ this ->time = $ time ;
160158 $ this ->dispatcher = $ dispatcher ;
161159
162160 $ this ->adapter = $ adapter ;
@@ -198,7 +196,7 @@ public static function create(
198196 return new static (
199197 $ container ->get ('cache_contexts_manager ' ),
200198 $ container ->get ('cache.graphql.results ' ),
201- $ container ->get ('request_stack ' ),
199+ $ container ->get ('datetime.time ' ),
202200 $ container ->get ('event_dispatcher ' ),
203201 $ adapter ,
204202 $ schema ,
@@ -444,8 +442,7 @@ protected function cacheWrite($prefix, CacheableExecutionResult $result) {
444442 * @see \Drupal\Core\Cache\CacheBackendInterface::set()
445443 */
446444 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 ();
449446 return ($ maxAge === Cache::PERMANENT ) ? Cache::PERMANENT : (int ) $ time + $ maxAge ;
450447 }
451448
0 commit comments