silverstripe-cms/code/GraphQL/_legacy/ReadOneResolver.php
Aaron Carlino 5ab1ff3e69
NEW: GraphQL Compatibility (#2607)
* Add GraphQL4 compatibility

* Add getPageByLink

* Blacklist sitetree fields

* Remove getByLink from default schema. use linkable plugin

* getByLink compatability with new readOne filter anything

* Remove return type

* Compliance with new modelConfig

* Prep for travis

* Improvements for versioned-admin compat

* BC class guards

* New graphql 3 compat

* Fix travis syntax error

* New backward graphqlphp dependency

* Lint, build

* New phpcs exclusion

* Tidy up travis

* Fix rollback mutation

* Update code/GraphQL/_legacy/ReadOneResolver.php

Co-authored-by: Ingo Schommer <ingo@silverstripe.com>

* Address ingo feedback

* Deprecated GraphQL v3 classes

* Remove deleted branches

Co-authored-by: Ingo Schommer <ingo@silverstripe.com>
Co-authored-by: Ingo Schommer <me@chillu.com>
2020-11-13 13:50:44 +13:00

33 lines
912 B
PHP

<?php
namespace SilverStripe\CMS\GraphQL;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\GraphQL\Scaffolding\Scaffolders\CRUD\ReadOne;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
use SilverStripe\ORM\DataList;
if (!class_exists(ReadOne::class)) {
return;
}
/**
* Shim to make readOnePage work like GraphQL 4
*
* @internal Use GraphQL v4
* @deprecated 4.8..5.0 Use silverstripe/graphql:^4 functionality.
*/
class ReadOneResolver
{
public static function resolve($obj, array $args, array $context, ResolveInfo $info)
{
$idKey = StaticSchema::inst()->formatField('ID');
$id = $args['filter'][$idKey]['eq'];
$readOne = Injector::inst()->createWithArgs(ReadOne::class, ['Page']);
unset($args['filter']);
$args[$idKey] = $id;
return $readOne->resolve($obj, $args, $context, $info);
}
}