From 106fe2777dd3314dc750c5a4aade8a5822a32ab1 Mon Sep 17 00:00:00 2001 From: Peter Philipp Date: Tue, 23 Jul 2024 11:36:45 +0200 Subject: [PATCH] feat: Add a way to pass arguments to operators. Why this wasn't added to the operator call in \Pimcore\Bundle\DataHubBundle\GraphQL\Resolver\Base::resolve() in the first place is a mystery - dropping information just like that is a shame. And now we can't simply adjusting the interface without breaking stuff but have to create more interfaces. --- .../ArgumentsAwareOperatorInterface.php | 25 +++++++++++++++++++ .../ContextAwareOperatorInterface.php | 25 +++++++++++++++++++ src/GraphQL/Resolver/Base.php | 11 ++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/GraphQL/Query/Operator/ArgumentsAwareOperatorInterface.php create mode 100644 src/GraphQL/Query/Operator/ContextAwareOperatorInterface.php diff --git a/src/GraphQL/Query/Operator/ArgumentsAwareOperatorInterface.php b/src/GraphQL/Query/Operator/ArgumentsAwareOperatorInterface.php new file mode 100644 index 00000000..1dc3d8ec --- /dev/null +++ b/src/GraphQL/Query/Operator/ArgumentsAwareOperatorInterface.php @@ -0,0 +1,25 @@ +fieldName] ?? null; // check for alias as we cache the properties with aliases @@ -86,6 +91,12 @@ public function resolve($value = null, $args = [], $context = [], ResolveInfo $r } /** @var \Pimcore\Bundle\DataHubBundle\GraphQL\Query\Operator\AbstractOperator $operatorImpl */ $operatorImpl = $this->getGraphQlService()->buildQueryOperator($this->typeName, $this->attributes); + if ($operatorImpl instanceof ArgumentsAwareOperatorInterface) { + $operatorImpl->setArguments($args ?? []); + } + if ($operatorImpl instanceof ContextAwareOperatorInterface) { + $operatorImpl->setContext($context ?? []); + } $element = $this->loadDataElement($value, 'object'); $valueFromOperator = $operatorImpl->getLabeledValue($element, $resolveInfo);