From 0ea4415d8ef9aa9b6d1f5939ad74fef84252d1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dezs=C5=91=20BICZ=C3=93?= Date: Mon, 14 Aug 2023 10:00:37 +0200 Subject: [PATCH] fix(DataProducer): Fix missing cacheability bubble up on entity translations data producer --- src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php | 5 ++++- .../GraphQL/DataProducer/Entity/EntityTranslations.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php index 633bdc29d..1a30c65dc 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php @@ -8,6 +8,7 @@ use Drupal\Core\Entity\TranslatableInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\graphql\GraphQL\Execution\FieldContext; use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -97,10 +98,11 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition, * @param bool|null $access * @param \Drupal\Core\Session\AccountInterface|null $accessUser * @param string|null $accessOperation + * @param \Drupal\graphql\GraphQL\Execution\FieldContext $context * * @return \Drupal\Core\Entity\EntityInterface|null */ - public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) { + public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) { if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) { $entity = $entity->getTranslation($language); $entity->addCacheContexts(["static:language:{$language}"]); @@ -109,6 +111,7 @@ public function resolve(EntityInterface $entity, $language, ?bool $access, ?Acco if ($access) { /** @var \Drupal\Core\Access\AccessResultInterface $accessResult */ $accessResult = $entity->access($accessOperation, $accessUser, TRUE); + $context->addCacheableDependency($accessResult); if (!$accessResult->isAllowed()) { return NULL; } diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslations.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslations.php index 5a68d8e89..7f0d0f0c5 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslations.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityTranslations.php @@ -9,6 +9,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\graphql\GraphQL\Execution\FieldContext; use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -96,10 +97,11 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition, * @param bool|null $access * @param \Drupal\Core\Session\AccountInterface|null $accessUser * @param string|null $accessOperation + * @param \Drupal\graphql\GraphQL\Execution\FieldContext $context * * @return array|null */ - public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) { + public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) { if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) { $languages = $entity->getTranslationLanguages(); @@ -110,6 +112,7 @@ public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterfac if ($access) { /** @var \Drupal\Core\Access\AccessResultInterface $accessResult */ $accessResult = $entity->access($accessOperation, $accessUser, TRUE); + $context->addCacheableDependency($accessResult); if (!$accessResult->isAllowed()) { return NULL; }