Skip to content

Commit

Permalink
Merge pull request #16439 from craftcms/bugfix/16433-gql-eager-loadin…
Browse files Browse the repository at this point in the history
…g-plans-and-relations

handling of relatedTo<XYZ> arguments in eager loading plans
  • Loading branch information
brandonkelly authored Jan 15, 2025
2 parents 461a5f9 + 6e50120 commit b1abfb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
10 changes: 10 additions & 0 deletions src/gql/ArgumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b1abfb3

Please sign in to comment.