cacheableQuery = $cacheableQuery; $this->cacheIdCalculator = $cacheIdCalculator; $this->config = $config; $this->logger = $logger; $this->requestProcessor = $requestProcessor; $this->registry = $registry; } /** * Process graphql headers * * @param FrontControllerInterface $subject * @param RequestInterface $request * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch( FrontControllerInterface $subject, RequestInterface $request ): void { try { $this->requestProcessor->validateRequest($request); } catch (\Exception $error) { $this->logger->critical($error->getMessage()); } /** @var \Magento\Framework\App\Request\Http $request */ $this->requestProcessor->processHeaders($request); $this->request = $request; } /** * Plugin for GraphQL after render from dispatch to set tag and cache headers * * @param ResultInterface $subject * @param ResultInterface $result * @param ResponseHttp $response * @return ResultInterface * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterRenderResult(ResultInterface $subject, ResultInterface $result, ResponseHttp $response) { if (!$this->config->isEnabled() || $this->request && str_contains($this->request->getContent(), 'mutation')) { $response->setNoCacheHeaders(); return $result; } /** @see \Magento\Framework\App\Http::launch */ /** @see \Magento\PageCache\Model\Controller\Result\BuiltinPlugin::afterRenderResult */ $this->registry->register('use_page_cache_plugin', true, true); $cacheId = $this->cacheIdCalculator->getCacheId(); if ($cacheId) { $response->setHeader(CacheIdCalculator::CACHE_ID_HEADER, $cacheId, true); } if (!$this->cacheableQuery->shouldPopulateCacheHeadersWithTags()) { $response->setNoCacheHeaders(); return $result; } $response->setPublicHeaders($this->config->getTtl()); $response->setHeader('X-Magento-Tags', implode(',', $this->cacheableQuery->getCacheTags()), true); return $result; } }