Skip to content

Commit

Permalink
Add QueryType for Version on Objects (#837)
Browse files Browse the repository at this point in the history
* Update PimcoreObjectType.php

* Apply php-cs-fixer changes

* Update src/GraphQL/DataObjectType/PimcoreObjectType.php

---------

Co-authored-by: leitge <[email protected]>
  • Loading branch information
leitge and leitge authored Jul 5, 2024
1 parent a0078a2 commit 127f620
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/GraphQL/DataObjectType/PimcoreObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ public function build($context = [])
'id' => Type::id(),
'creationDate' => Type::int(),
'modificationDate' => Type::int(),
'version' => [
'type' => Type::int(),
'resolve' => function ($value = null, $args = [], $context = [], ResolveInfo $resolveInfo = null) {
$object = \Pimcore\Model\DataObject::getById($value['id']);
if ($object) {
foreach (array_reverse($object->getVersions()) as $version) {
if ($object->getModificationDate() === $version->getDate()) {
return $version->getId();
}
}
}

return null;
}
],
'objectType' => [
'type' => Type::string(),
'resolve' => function ($value = null, $args = [], $context = [], ResolveInfo $resolveInfo = null) {
Expand Down

0 comments on commit 127f620

Please sign in to comment.