PHP Fatal error: Uncaught TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null

Created on 3 June 2025, 4 days ago

Problem/Motivation

Using GraphQL 3.x along with the graphql_core module. When upgrading to Drupal 11 I get the following error message (on drush cr, for example):

PHP Fatal error:  Uncaught TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /app/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 243 and defined in /app/web/core/lib/Drupal/Component/Utility/Html.php:431
Stack trace:
#0 /app/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(243): Drupal\Component\Utility\Html::escape()
#1 /app/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(187): Drupal\Component\Render\FormattableMarkup::placeholderEscape()
#2 /app/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat()
#3 /app/web/core/lib/Drupal/Component/Utility/ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render()
#4 /app/web/modules/contrib/graphql/src/Plugin/GraphQL/Traits/DescribablePluginTrait.php(14): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
#5 /app/web/modules/contrib/graphql/src/Plugin/GraphQL/Fields/FieldPluginBase.php(103): Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase->buildDescription()
#6 /app/web/modules/contrib/graphql/src/Plugin/Deriver/PluggableSchemaDeriver.php(373): Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase->getDefinition()
#7 [internal function]: Drupal\graphql\Plugin\Deriver\PluggableSchemaDeriver->Drupal\graphql\Plugin\Deriver\{closure}()
#8 /app/web/modules/contrib/graphql/src/Plugin/Deriver/PluggableSchemaDeriver.php(365): array_reduce()
#9 [internal function]: Drupal\graphql\Plugin\Deriver\PluggableSchemaDeriver->Drupal\graphql\Plugin\Deriver\{closure}()
#10 /app/web/modules/contrib/graphql/src/Plugin/Deriver/PluggableSchemaDeriver.php(364): array_reduce()
#11 /app/web/modules/contrib/graphql/src/Plugin/Deriver/PluggableSchemaDeriver.php(104): Drupal\graphql\Plugin\Deriver\PluggableSchemaDeriver->buildFieldMap()
#12 /app/web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(101): Drupal\graphql\Plugin\Deriver\PluggableSchemaDeriver->getDerivativeDefinitions()
#13 /app/web/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php(87): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives()
#14 /app/web/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(337): Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions()
#15 /app/web/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(213): Drupal\Core\Plugin\DefaultPluginManager->findDefinitions()
#16 /app/web/modules/contrib/graphql/src/Routing/QueryRoutes.php(54): Drupal\Core\Plugin\DefaultPluginManager->getDefinitions()
#17 /app/web/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php(37): Drupal\graphql\Routing\QueryRoutes->alterRoutes()
#18 /app/vendor/symfony/event-dispatcher/EventDispatcher.php(246): Drupal\Core\Routing\RouteSubscriberBase->onAlterRoutes()
#19 /app/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}()
#20 /app/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
#21 /app/web/core/lib/Drupal/Core/Routing/RouteBuilder.php(189): Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
#22 /app/web/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild()
#23 /app/web/core/includes/common.inc(459): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild()
#24 /app/web/core/includes/utility.inc(41): drupal_flush_all_caches()
#25 /app/vendor/drush/drush/src/Commands/core/CacheRebuildCommands.php(60): drupal_rebuild()
#26 [internal function]: Drush\Commands\core\CacheRebuildCommands->rebuild()
#27 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
#28 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#29 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#30 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process()
#31 /app/vendor/symfony/console/Command/Command.php(279): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#32 /app/vendor/symfony/console/Application.php(1094): Symfony\Component\Console\Command\Command->run()
#33 /app/vendor/symfony/console/Application.php(342): Symfony\Component\Console\Application->doRunCommand()
#34 /app/vendor/symfony/console/Application.php(193): Symfony\Component\Console\Application->doRun()
#35 /app/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
#36 /app/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
#37 /app/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run()
#38 /app/vendor/drush/drush/drush(4): require('...')
#39 {main}
  thrown in /app/web/core/lib/Drupal/Component/Utility/Html.php on line 431

Looks like the graphql_core module isn't aware that \Drupal\Core\Field\FieldStorageDefinitionInterface::getDescription() is able to return NULL.

Proposed resolution

Check if the field actually has a description before adding it to the definition.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇧🇪Belgium rp7

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024