Skip to content

Commit 970fd59

Browse files
authored
Merge pull request #650 from favicode/fix/remove-graphql-dependency
Fix for problem with removing GraphQl module
2 parents 033bc26 + fb69e71 commit 970fd59

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

Plugin/GraphQl/AfterRenderResult.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
namespace Fastly\Cdn\Plugin\GraphQl;
55

66
use Fastly\Cdn\Model\Config;
7+
use Magento\Framework\App\ObjectManager;
78
use Magento\Framework\App\ResponseInterface;
89
use Magento\Framework\Controller\ResultInterface;
9-
use Magento\GraphQlCache\Model\CacheableQuery;
10+
use Magento\Framework\Module\Manager;
1011

1112
class AfterRenderResult
1213
{
@@ -16,22 +17,22 @@ class AfterRenderResult
1617
private $config;
1718

1819
/**
19-
* @var CacheableQuery
20+
* @var Manager
2021
*/
21-
private $cacheableQuery;
22+
private $moduleManager;
2223

2324
/**
2425
* AfterRenderResult constructor.
2526
*
2627
* @param Config $config
27-
* @param CacheableQuery $cacheableQuery
28+
* @param Manager $moduleManager
2829
*/
2930
public function __construct(
3031
Config $config,
31-
CacheableQuery $cacheableQuery
32+
Manager $moduleManager
3233
) {
3334
$this->config = $config;
34-
$this->cacheableQuery = $cacheableQuery;
35+
$this->moduleManager = $moduleManager;
3536
}
3637

3738
/**
@@ -47,21 +48,29 @@ public function afterRenderResult(
4748
ResultInterface $result,
4849
ResponseInterface $response
4950
): ResultInterface {
50-
if ($this->config->isEnabled()
51-
&& $this->config->getType() === Config::FASTLY
52-
&& $this->cacheableQuery->isCacheable()) {
53-
$header = $response->getHeader('cache-control');
5451

55-
if ($header) {
56-
if ($ttl = $this->config->getStaleTtl()) {
57-
$header->addDirective('stale-while-revalidate', $ttl);
58-
}
52+
if (!$this->config->isEnabled() || !($this->config->getType() === Config::FASTLY)) {
53+
return $result;
54+
}
55+
56+
if (!$this->moduleManager->isEnabled('Magento_GraphQlCache') ||
57+
!ObjectManager::getInstance()->get(\Magento\GraphQlCache\Model\CacheableQuery::class)->isCacheable()
58+
) {
59+
return $result;
60+
}
61+
62+
$header = $response->getHeader('cache-control');
5963

60-
if ($ttl = $this->config->getStaleErrorTtl()) {
61-
$header->addDirective('stale-if-error', $ttl);
62-
}
64+
if ($header) {
65+
if ($ttl = $this->config->getStaleTtl()) {
66+
$header->addDirective('stale-while-revalidate', $ttl);
67+
}
68+
69+
if ($ttl = $this->config->getStaleErrorTtl()) {
70+
$header->addDirective('stale-if-error', $ttl);
6371
}
6472
}
73+
6574
return $result;
6675
}
6776
}

0 commit comments

Comments
 (0)