diff --git a/CHANGELOG.md b/CHANGELOG.md index ad1912167e7..4321be27a40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 5 +## Unreleased + +- Fixed an error that could occur when setting `relatedTo*` GraphQL arguments to `null`. ([#16433](https://github.com/craftcms/cms/issues/16433)) + ## 5.5.10 - 2025-01-14 - Fixed a bug where the control panel could display a notice about the Craft CMS license belonging to a different domain, even when accessing the control panel from the correct domain. ([#16396](https://github.com/craftcms/cms/issues/16396)) diff --git a/src/gql/ArgumentManager.php b/src/gql/ArgumentManager.php index bf523affc49..8817bf6fe0f 100644 --- a/src/gql/ArgumentManager.php +++ b/src/gql/ArgumentManager.php @@ -12,6 +12,7 @@ use craft\errors\GqlException; use craft\events\RegisterGqlArgumentHandlersEvent; use craft\gql\base\ArgumentHandlerInterface; +use craft\gql\base\RelationArgumentHandler; use craft\gql\handlers\RelatedAssets; use craft\gql\handlers\RelatedCategories; use craft\gql\handlers\RelatedEntries; @@ -153,6 +154,15 @@ public function prepareArguments(array $arguments): array if (!empty($arguments[$argumentName]) && $handler instanceof ArgumentHandlerInterface) { $arguments = $handler->handleArgumentCollection($arguments); } + // if it's one of the relatedToXYZ arguments, + // if the value is empty/null unset that arg so that it doesn't go into the criteria + if ( + array_key_exists($argumentName, $arguments) && + empty($arguments[$argumentName]) && + $handler instanceof RelationArgumentHandler + ) { + unset($arguments[$argumentName]); + } } return $arguments;