|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\SchemaConfigurators; |
|
6
|
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\General\BlockHelpers; |
|
8
|
|
|
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade; |
|
9
|
|
|
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade; |
|
10
|
|
|
use GraphQLAPI\GraphQLAPI\Blocks\SchemaConfigCacheControlListBlock; |
|
11
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\PerformanceFunctionalityModuleResolver; |
|
12
|
|
|
use GraphQLAPI\GraphQLAPI\SchemaConfigurators\CacheControlGraphQLQueryConfigurator; |
|
13
|
|
|
use GraphQLAPI\GraphQLAPI\SchemaConfigurators\AbstractQueryExecutionSchemaConfigurator; |
|
14
|
|
|
|
|
15
|
|
|
class PersistedQuerySchemaConfigurator extends AbstractQueryExecutionSchemaConfigurator |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Apply all the settings defined in the Schema Configuration: |
|
19
|
|
|
* - Access Control Lists |
|
20
|
|
|
* - Cache Control Lists |
|
21
|
|
|
* - Field Deprecation Lists |
|
22
|
|
|
* |
|
23
|
|
|
* @param integer $schemaConfigurationID |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function executeSchemaConfigurationItems(int $schemaConfigurationID): void |
|
27
|
|
|
{ |
|
28
|
|
|
parent::executeSchemaConfigurationItems($schemaConfigurationID); |
|
29
|
|
|
|
|
30
|
|
|
// Also execute the Cache Control |
|
31
|
|
|
$this->executeSchemaConfigurationCacheControlLists($schemaConfigurationID); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Apply all the settings defined in the Schema Configuration for: |
|
36
|
|
|
* - Cache Control Lists |
|
37
|
|
|
* |
|
38
|
|
|
* @param integer $schemaConfigurationID |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function executeSchemaConfigurationCacheControlLists(int $schemaConfigurationID): void |
|
42
|
|
|
{ |
|
43
|
|
|
// Do not execute Cache Control when previewing the query |
|
44
|
|
|
if (\is_preview()) { |
|
45
|
|
|
return; |
|
46
|
|
|
} |
|
47
|
|
|
// Check it is enabled by module |
|
48
|
|
|
$moduleRegistry = ModuleRegistryFacade::getInstance(); |
|
49
|
|
|
if (!$moduleRegistry->isModuleEnabled(PerformanceFunctionalityModuleResolver::CACHE_CONTROL)) { |
|
50
|
|
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
$instanceManager = InstanceManagerFacade::getInstance(); |
|
53
|
|
|
/** |
|
54
|
|
|
* @var SchemaConfigCacheControlListBlock |
|
55
|
|
|
*/ |
|
56
|
|
|
$block = $instanceManager->getInstance(SchemaConfigCacheControlListBlock::class); |
|
57
|
|
|
$schemaConfigCCLBlockDataItem = BlockHelpers::getSingleBlockOfTypeFromCustomPost( |
|
58
|
|
|
$schemaConfigurationID, |
|
59
|
|
|
$block |
|
60
|
|
|
); |
|
61
|
|
|
if (!is_null($schemaConfigCCLBlockDataItem)) { |
|
62
|
|
|
if ($cacheControlLists = $schemaConfigCCLBlockDataItem['attrs'][SchemaConfigCacheControlListBlock::ATTRIBUTE_NAME_CACHE_CONTROL_LISTS] ?? null) { |
|
63
|
|
|
$configurator = new CacheControlGraphQLQueryConfigurator(); |
|
64
|
|
|
foreach ($cacheControlLists as $cacheControlListID) { |
|
65
|
|
|
$configurator->executeSchemaConfiguration($cacheControlListID); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|