Skip to content

Commit 17e33a9

Browse files
davidwhthomasfubhy
authored andcommitted
#737 Add cache contexts in ContextDeriver. (#865)
1 parent 66e87f6 commit 17e33a9

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
88
use Drupal\graphql\Utility\StringHelper;
99
use Symfony\Component\DependencyInjection\ContainerInterface;
10+
use Drupal\Core\Cache\CacheableDependencyInterface;
1011

1112
class ContextDeriver extends DeriverBase implements ContainerDeriverInterface {
1213

@@ -44,7 +45,13 @@ public function getDerivativeDefinitions($basePluginDefinition) {
4445
'name' => StringHelper::propCase($id, 'context'),
4546
'context_id' => $id,
4647
'type' => $context->getContextDefinition()->getDataType(),
47-
] + $basePluginDefinition;
48+
];
49+
// Add cache contexts, if available
50+
if ($context instanceof CacheableDependencyInterface) {
51+
$this->derivatives[$id]['response_cache_contexts'] = $context->getCacheContexts();
52+
}
53+
// Add default base
54+
$this->derivatives[$id] += $basePluginDefinition;
4855
}
4956
}
5057

0 commit comments

Comments
 (0)