diff --git a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php index 1bcd6248b..4a62dee09 100644 --- a/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php +++ b/src/Plugin/GraphQL/DataProducer/Taxonomy/TaxonomyLoadTree.php @@ -160,14 +160,15 @@ public function resolve(string $vid, int $parent, ?int $max_depth, ?string $lang return new Deferred(function () use ($language, $resolver, $context, $access, $accessUser, $accessOperation) { /** @var \Drupal\Core\Entity\EntityInterface[] $entities */ $entities = $resolver(); + + // Add the list cache tags so that the cache entry is purged + // whenever a new entity of this type is saved. + $type = $this->entityTypeManager->getDefinition('taxonomy_term'); + /** @var \Drupal\Core\Entity\EntityTypeInterface $type */ + $tags = $type->getListCacheTags(); + $context->addCacheTags($tags); + if (!$entities) { - // If there is no entity with this id, add the list cache tags so that - // the cache entry is purged whenever a new entity of this type is - // saved. - $type = $this->entityTypeManager->getDefinition('taxonomy_term'); - /** @var \Drupal\Core\Entity\EntityTypeInterface $type */ - $tags = $type->getListCacheTags(); - $context->addCacheTags($tags); return []; }