From af60321ede0746666f36ba5cd0dfe0468440296e Mon Sep 17 00:00:00 2001 From: i-just Date: Wed, 15 Jan 2025 15:38:18 +0000 Subject: [PATCH 1/2] don't allow special relatedToXYZ arguments to make it into query criteria --- src/gql/ArgumentManager.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gql/ArgumentManager.php b/src/gql/ArgumentManager.php index 93c7ec10895..78830d77c73 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; @@ -154,6 +155,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; From 6e50120b52f24c747174d3dc022a4add30912601 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 15 Jan 2025 09:26:58 -0800 Subject: [PATCH 2/2] Release note [ci skip] --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48066f3311a..304c94f3089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 4 +## Unreleased + +- Fixed an error that could occur when setting `relatedTo*` GraphQL arguments to `null`. ([#16433](https://github.com/craftcms/cms/issues/16433)) + ## 4.13.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))