From 2418c4ecef7d26c1681484bfb975cba8060e2e2f Mon Sep 17 00:00:00 2001 From: Oleksii Tsulun Date: Thu, 28 May 2020 15:51:01 -0400 Subject: [PATCH] fix entity_load data producer when no translation available. --- src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php index 765632a8c..d637a3a7c 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLoad.php @@ -161,8 +161,13 @@ public function resolve($type, $id, $language, ?array $bundles, ?bool $access, ? // Get the correct translation. if (isset($language) && $language !== $entity->language()->getId() && $entity instanceof TranslatableInterface) { - $entity = $entity->getTranslation($language); - $entity->addCacheContexts(["static:language:{$language}"]); + if ($entity->hasTranslation($language)) { + $entity = $entity->getTranslation($language); + $entity->addCacheContexts(["static:language:{$language}"]); + } + else { + return NULL; + } } // Check if the passed user (or current user if none is passed) has access