Skip to content

Commit 46e0bc6

Browse files
authored
Simplify and reduce cache metadata of responses (#686)
1 parent a2ef916 commit 46e0bc6

21 files changed

Lines changed: 14 additions & 145 deletions

modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldDeriver.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ protected function getDerivativeDefinitionsFromFieldDefinition($entityTypeId, Fi
3434
'schema_cache_tags' => $tags,
3535
'schema_cache_contexts' => $contexts,
3636
'schema_cache_max_age' => $maxAge,
37-
'response_cache_tags' => $tags,
38-
'response_cache_contexts' => $contexts,
39-
'response_cache_max_age' => $maxAge,
4037
] + $basePluginDefinition;
4138

4239
if (count($propertyDefinitions) === 1) {

modules/graphql_core/src/Plugin/Deriver/Fields/EntityFieldItemDeriver.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ protected function getDerivativeDefinitionsFromFieldDefinition($entityTypeId, Fi
2828
'schema_cache_tags' => $tags,
2929
'schema_cache_contexts' => $contexts,
3030
'schema_cache_max_age' => $maxAge,
31-
'response_cache_tags' => $tags,
32-
'response_cache_contexts' => $contexts,
33-
'response_cache_max_age' => $maxAge,
3431
] + $basePluginDefinition;
3532

3633
$derivatives = [];

modules/graphql_core/src/Plugin/Deriver/Fields/EntityReferenceQueryDeriver.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ public function getDerivativeDefinitions($basePluginDefinition) {
101101
'schema_cache_tags' => $tags,
102102
'schema_cache_contexts' => $contexts,
103103
'schema_cache_max_age' => $maxAge,
104-
'response_cache_tags' => $tags,
105-
'response_cache_contexts' => $contexts,
106-
'response_cache_max_age' => $maxAge,
107104
] + $basePluginDefinition;
108105

109106
/** @var \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface $definition */

modules/graphql_core/src/Plugin/Deriver/Fields/EntityReferenceReverseDeriver.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ public function getDerivativeDefinitions($basePluginDefinition) {
9898
'schema_cache_tags' => $tags,
9999
'schema_cache_contexts' => $contexts,
100100
'schema_cache_max_age' => $maxAge,
101-
'response_cache_tags' => $tags,
102-
'response_cache_contexts' => $contexts,
103-
'response_cache_max_age' => $maxAge,
104101
] + $basePluginDefinition;
105102

106103
/** @var \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface $definition */

modules/graphql_core/src/Plugin/GraphQL/Fields/Blocks/BlocksByRegion.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ protected function resolveValues($value, array $args, ResolveContext $context, R
143143
return function ($value, array $args, ResolveContext $context, ResolveInfo $info) use ($resolve) {
144144
/** @var \Drupal\graphql\GraphQL\Cache\CacheableValue $response */
145145
$response = $resolve();
146-
$metadata = new CacheableMetadata();
147-
$metadata->addCacheTags(['config:block_list']);
148146
$blocks = array_map(function (Block $block) {
149147
$plugin = $block->getPlugin();
150148
if ($plugin instanceof BlockContentBlock) {
@@ -156,7 +154,7 @@ protected function resolveValues($value, array $args, ResolveContext $context, R
156154
}, $response->getValue());
157155

158156
foreach ($blocks as $block) {
159-
yield new CacheableValue($block, [$metadata, $response]);
157+
yield new CacheableValue($block, [$response]);
160158
}
161159
};
162160
}

modules/graphql_core/tests/src/Kernel/Blocks/BlockTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,10 @@ protected function setUp() {
6666
public function testStaticBlocks() {
6767
$query = $this->getQueryFromFile('Blocks/blocks.gql');
6868
$metadata = $this->defaultCacheMetaData();
69-
70-
// TODO: Check cache metadata.
7169
$metadata->addCacheTags([
72-
'config:block_list',
7370
'block_content:1',
71+
// TODO: Check metatags. Is the config metatag required?
7472
'config:block.block.stark_powered',
75-
'config:field.storage.block_content.body',
76-
'entity_field_info',
7773
]);
7874

7975
$this->assertResults($query, [], [

modules/graphql_core/tests/src/Kernel/Breadcrumbs/BreadcrumbsTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ protected function setUp() {
4949
*/
5050
public function testBreadcrumbs() {
5151
$query = $this->getQueryFromFile('breadcrumbs.gql');
52-
53-
// TODO: Check cache metadata.
5452
$metadata = $this->defaultCacheMetaData();
55-
$metadata->setCacheTags(array_diff($metadata->getCacheTags(), ['entity_bundles']));
5653

5754
$this->assertResults($query, ['path' => '/breadcrumbs-test'], [
5855
'route' => [

modules/graphql_core/tests/src/Kernel/Context/ContextTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class ContextTest extends GraphQLCoreTestBase {
2020
*/
2121
public function testSimpleContext() {
2222
$query = $this->getQueryFromFile('context.gql');
23-
24-
// TODO: Check cache metadata.
2523
$metadata = $this->defaultCacheMetaData();
26-
$metadata->setCacheTags(array_diff($metadata->getCacheTags(), ['entity_bundles']));
2724

2825
$this->assertResults($query, [], [
2926
'a' => ['name' => 'graphql_context_test.a'],

modules/graphql_core/tests/src/Kernel/Entity/EntityFieldValueTest.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ public function testBoolean() {
6666

6767
$metadata = $this->defaultCacheMetaData();
6868

69-
70-
$metadata->addCacheTags([
71-
'config:field.storage.node.field_boolean',
72-
'entity_field_info',
73-
]);
74-
7569
$this->assertResults($query, [], [
7670
'node' => [
7771
'fieldBoolean' => TRUE,
@@ -110,10 +104,6 @@ public function testText() {
110104
GQL;
111105

112106
$metadata = $this->defaultCacheMetaData();
113-
$metadata->addCacheTags([
114-
'config:field.storage.node.field_text',
115-
'entity_field_info',
116-
]);
117107

118108
$this->assertResults($query, [], [
119109
'node' => [
@@ -161,10 +151,6 @@ public function testFilteredText() {
161151
GQL;
162152

163153
$metadata = $this->defaultCacheMetaData();
164-
$metadata->addCacheTags([
165-
'config:field.storage.node.body',
166-
'entity_field_info',
167-
]);
168154

169155
$this->assertResults($query, [], [
170156
'node' => [
@@ -253,21 +239,6 @@ public function testRawValues($actualFieldValues, $expectedFieldValues) {
253239

254240
$metadata = $this->defaultCacheMetaData();
255241
$metadata->addCacheTags([
256-
'config:field.storage.node.body',
257-
'config:field.storage.node.field_text',
258-
'config:field.storage.node.field_boolean',
259-
'config:field.storage.node.field_datetime',
260-
'config:field.storage.node.field_decimal',
261-
'config:field.storage.node.field_email',
262-
'config:field.storage.node.field_float',
263-
'config:field.storage.node.field_file',
264-
'config:field.storage.node.field_image',
265-
'config:field.storage.node.field_integer',
266-
'config:field.storage.node.field_link',
267-
'config:field.storage.node.field_string',
268-
'config:field.storage.node.field_timestamp',
269-
'config:field.storage.node.field_reference',
270-
'entity_field_info',
271242
'node:1',
272243
'user:0',
273244
'file:1',

modules/graphql_core/tests/src/Kernel/GraphQLContentTestBase.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ class GraphQLContentTestBase extends GraphQLCoreTestBase {
3030
'text',
3131
];
3232

33-
/**
34-
* {@inheritdoc}
35-
*/
36-
protected function defaultCacheTags() {
37-
return array_merge([
38-
'config:field.storage.node.body',
39-
], parent::defaultCacheTags());
40-
}
41-
4233
/**
4334
* {@inheritdoc}
4435
*

0 commit comments

Comments
 (0)