diff --git a/_legacy/GraphQL/ReadOneLegacyResolver.php b/_legacy/GraphQL/ReadOneLegacyResolver.php new file mode 100644 index 000000000..93c4c99a9 --- /dev/null +++ b/_legacy/GraphQL/ReadOneLegacyResolver.php @@ -0,0 +1,48 @@ +dataObject = $dataObject; + } + + public function resolve($object, array $args, $context, ResolveInfo $info) + { + if (!$this->dataObject->canView($context['currentUser'])) { + throw new \Exception(sprintf('Cannot view %s', $this->dataObject->singular_name())); + } + + $idKey = StaticSchema::inst()->formatField('ID'); + $id = $args['filter'][$idKey]['eq']; + $readOne = Injector::inst()->createWithArgs(ReadOne::class, [$this->dataObject->baseClass()]); + unset($args['filter']); + $args[$idKey] = $id; + + return $readOne->resolve($object, $args, $context, $info); + } +}