Skip to content

Commit f03d8d8

Browse files
committed
Adding cache contexts.
1 parent 9009883 commit f03d8d8

5 files changed

Lines changed: 15 additions & 1 deletion

File tree

modules/graphql_core/src/Plugin/Deriver/Types/EntityTypeDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3434
'interfaces' => $this->getInterfaces($type, $basePluginDefinition),
3535
'entity_type' => $typeId,
3636
] + $basePluginDefinition;
37-
37+
3838
if ($typeId === 'node') {
3939
// TODO: Make this more generic somehow.
4040
$derivative['response_cache_contexts'][] = 'user.node_grants:view';

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public function testEntityByIdWithTranslation() {
7878
'node:1',
7979
]);
8080

81+
$metadata->addCacheContexts(['user.node_grants:view']);
82+
8183
// Check English node.
8284
$this->assertResults($this->getQueryFromFile('entity_by_id.gql'), [
8385
'id' => $node->id(),

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public function testBoolean() {
7070
'entity_field_info',
7171
]);
7272

73+
$metadata->addCacheContexts(['user.node_grants:view']);
74+
7375
$this->assertResults($query, [], [
7476
'node' => [
7577
'fieldBoolean' => TRUE,
@@ -113,6 +115,8 @@ public function testText() {
113115
'entity_field_info',
114116
]);
115117

118+
$metadata->addCacheContexts(['user.node_grants:view']);
119+
116120
$this->assertResults($query, [], [
117121
'node' => [
118122
'fieldText' => [
@@ -164,6 +168,8 @@ public function testFilteredText() {
164168
'entity_field_info',
165169
]);
166170

171+
$metadata->addCacheContexts(['user.node_grants:view']);
172+
167173
$this->assertResults($query, [], [
168174
'node' => [
169175
'body' => [
@@ -249,6 +255,8 @@ public function testRawValues($actualFieldValues, $expectedFieldValues) {
249255
'file:2',
250256
]);
251257

258+
$metadata->addCacheContexts(['user.node_grants:view']);
259+
252260
$this->assertResults($this->getQueryFromFile('raw_field_values.gql'), [
253261
'path' => '/node/' . $node->id(),
254262
], [

modules/graphql_core/tests/src/Kernel/Images/ImageFieldTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public function testImageField() {
6464
'node:1',
6565
]);
6666

67+
$metadata->addCacheContexts(['user.node_grants:view']);
68+
6769
$this->assertResults($this->getQueryFromFile('image.gql'), [
6870
'path' => '/node/' . $a->id(),
6971
], [

modules/graphql_core/tests/src/Kernel/Routing/RouteEntityTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function testRouteEntity() {
2929
'node:1',
3030
]);
3131

32+
$metadata->addCacheContexts(['user.node_grants:view']);
33+
3234
$this->assertResults($query, $vars, [
3335
'route' => [
3436
'node' => [

0 commit comments

Comments
 (0)