Skip to content

Commit

Permalink
API Use SS_List as type
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 22, 2024
1 parent d90143c commit ee9b3f8
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 51 deletions.
8 changes: 4 additions & 4 deletions src/Modules/AssetAdmin/FileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Forms\DateField;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

class FileFilter
{
/**
* Caution: Does NOT enforce canView permissions
*
* @param Filterable $list
* @param SS_List $list
* @param array $filter
* @return Filterable
* @return SS_List
* @throws HTTPResponse_Exception
*/
public static function filterList(Filterable $list, $filter)
public static function filterList(SS_List $list, $filter)
{
// ID filtering
if (isset($filter['id']) && (int)$filter['id'] > 0) {
Expand Down
1 change: 0 additions & 1 deletion src/Modules/AssetAdmin/Resolvers/AssetAdminResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use SilverStripe\GraphQL\QueryHandler\UserContextProvider;
use SilverStripe\GraphQL\Schema\DataObject\FieldAccessor;
use SilverStripe\ORM\DataList;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Versioned\Versioned;
use InvalidArgumentException;

Expand Down
1 change: 0 additions & 1 deletion src/Modules/AssetAdmin/Resolvers/FolderTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use SilverStripe\GraphQL\Schema\Schema;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DB;
use SilverStripe\Model\List\Sortable;
use SilverStripe\Versioned\Versioned;
use InvalidArgumentException;
use Exception;
Expand Down
4 changes: 2 additions & 2 deletions src/Modules/Versioned/Plugins/VersionedDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
use SilverStripe\GraphQL\Schema\Type\ModelType;
use SilverStripe\GraphQL\Schema\Type\Type;
use SilverStripe\ORM\DataObject;
use SilverStripe\Model\List\Sortable;
use SilverStripe\Security\Member;
use SilverStripe\GraphQL\Modules\Versioned\Resolvers\VersionedResolver;
use SilverStripe\Versioned\Versioned;
use Closure;
use SilverStripe\Model\List\SS_List;
use SilverStripe\Model\ModelData;

// GraphQL dependency is optional in versioned,
Expand Down Expand Up @@ -131,7 +131,7 @@ public function apply(ModelType $type, Schema $schema, array $config = []): void
public static function sortVersions(array $config): Closure
{
$fieldName = $config['fieldName'];
return function (Sortable $list, array $args) use ($fieldName) {
return function (SS_List $list, array $args) use ($fieldName) {
$versionSort = $args[$fieldName]['version'] ?? null;
if ($versionSort) {
$list = $list->sort('Version', $versionSort);
Expand Down
15 changes: 7 additions & 8 deletions src/Schema/DataObject/Plugin/CanViewPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use SilverStripe\GraphQL\QueryHandler\UserContextProvider;
use SilverStripe\Core\ArrayLib;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Model\List\Filterable;
use InvalidArgumentException;
use SilverStripe\Model\List\SS_List;
use SilverStripe\Model\ArrayData;
Expand Down Expand Up @@ -37,7 +36,7 @@ protected function getPermissionResolver(): callable

/**
* @param mixed $obj
* @return Filterable|object|array|null
* @return SS_List|object|array|null
* @throws InvalidArgumentException
*/
public static function permissionCheck($obj, array $args, array $context, ResolveInfo $info)
Expand All @@ -57,7 +56,7 @@ public static function permissionCheck($obj, array $args, array $context, Resolv


if (is_object($obj)) {
return $obj instanceof Filterable
return $obj instanceof SS_List
? static::listPermissionCheck($obj, $args, $context, $info)
: static::itemPermissionCheck($obj, $args, $context, $info);
}
Expand All @@ -68,10 +67,10 @@ public static function permissionCheck($obj, array $args, array $context, Resolv
Otherwise, try returning an instance of %s or another implementation of %s.',
CanViewPermission::IDENTIFIER,
$info->fieldName,
Filterable::class,
SS_List::class,
AbstractCanViewPermission::class,
SS_List::class,
Filterable::class
SS_List::class
));
}

Expand Down Expand Up @@ -106,13 +105,13 @@ public static function itemPermissionCheck($obj, array $args, array $context, Re
}

/**
* @param Filterable $obj
* @param SS_List $obj
* @param array $args
* @param array $context
* @param ResolveInfo $info
* @return Filterable
* @return SS_List
*/
public static function listPermissionCheck(Filterable $obj, array $args, array $context, ResolveInfo $info): Filterable
public static function listPermissionCheck(SS_List $obj, array $args, array $context, ResolveInfo $info): SS_List
{
// Use an ArrayList rather than a DataList to ensure items returns all have had a canView() check run on them.
// Converting to an ArrayList will run a query and mean we start with a fixed number of items before
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/DataObject/Plugin/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\GraphQL\Schema\Schema;
use SilverStripe\Model\List\Limitable;
use SilverStripe\GraphQL\Schema\Plugin\PaginationPlugin;
use Closure;
use SilverStripe\Model\List\SS_List;

/**
* Adds pagination to a DataList query
Expand Down Expand Up @@ -35,7 +35,7 @@ public static function paginate(array $context): Closure
return null;
}

if (!$list instanceof Limitable) {
if (!$list instanceof SS_List) {
Schema::invariant(
!isset($list['nodes']),
'List on field %s has already been paginated. Was the plugin executed twice?',
Expand All @@ -51,7 +51,7 @@ public static function paginate(array $context): Closure
$limit = min($limit, $maxLimit);

// Apply limit
/* @var Limitable $list */
/* @var SS_List $list */
$limitedList = $list->limit($limit, $offset);
return static::createPaginationResult($total, $limitedList, $limit, $offset);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter;

use SilverStripe\ORM\DataList;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* Defines the interface used by all read filters for operations
*/
interface FieldFilterInterface
{
public function apply(Filterable $list, string $fieldName, $value): iterable;
public function apply(SS_List $list, string $fieldName, $value): iterable;

/**
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A filter that selects records that partially match a keyword
Expand All @@ -14,7 +14,7 @@ class ContainsFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':PartialMatch', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by the end of a field's contents
Expand All @@ -14,7 +14,7 @@ class EndsWithFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':EndsWith', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by exact match of a keyword
Expand All @@ -14,7 +14,7 @@ class EqualToFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':ExactMatch', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by greater than comparison
Expand All @@ -14,7 +14,7 @@ class GreaterThanFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':GreaterThan', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by greater than or equal comparison
Expand All @@ -14,7 +14,7 @@ class GreaterThanOrEqualFilter implements FieldFilterInterface
/**
* @inheritdoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':GreaterThanOrEqual', $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/DataObject/Plugin/QueryFilter/Filters/InFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\ListFieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by the presence of a value in an array
Expand All @@ -14,7 +14,7 @@ class InFilter implements ListFieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName, (array) $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by a less than comparison
Expand All @@ -14,7 +14,7 @@ class LessThanFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':LessThan', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by a less than or equal comparison
Expand All @@ -14,7 +14,7 @@ class LessThanOrEqualFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':LessThanOrEqual', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by negating an exact match
Expand All @@ -14,7 +14,7 @@ class NotEqualFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->exclude($fieldName, $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\Filters;

use SilverStripe\GraphQL\Schema\DataObject\Plugin\QueryFilter\FieldFilterInterface;
use SilverStripe\Model\List\Filterable;
use SilverStripe\Model\List\SS_List;

/**
* A query filter that filters records by the start of a field's content
Expand All @@ -14,7 +14,7 @@ class StartsWithFilter implements FieldFilterInterface
/**
* @inheritDoc
*/
public function apply(Filterable $list, string $fieldName, $value): iterable
public function apply(SS_List $list, string $fieldName, $value): iterable
{
return $list->filter($fieldName . ':StartsWith', $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/DataObject/Plugin/QueryFilter/QueryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use SilverStripe\GraphQL\Schema\Type\ModelType;
use SilverStripe\ORM\DataObject;
use Closure;
use SilverStripe\Model\List\Filterable;
use Exception;
use SilverStripe\Model\List\SS_List;

/**
* Adds a filter parameter to a DataObject query
Expand Down Expand Up @@ -80,7 +80,7 @@ public static function filter(array $context): Closure
$rootType = $context['rootType'];
$resolvers = $context['resolvers'] ?? [];

return function (?Filterable $list, array $args, array $context, ResolveInfo $info) use ($fieldName, $rootType, $resolvers) {
return function (?SS_List $list, array $args, array $context, ResolveInfo $info) use ($fieldName, $rootType, $resolvers) {
if ($list === null) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/DataObject/Plugin/QuerySort.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
use SilverStripe\GraphQL\Schema\Type\ModelType;
use SilverStripe\ORM\DataObject;
use Closure;
use SilverStripe\Model\List\Sortable;
use Exception;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\GraphQL\Schema\Traits\SortTrait;
use SilverStripe\Model\List\SS_List;

/**
* Adds a sort parameter to a DataObject query
Expand Down Expand Up @@ -99,7 +99,7 @@ public static function sort(array $context): closure
{
$fieldName = $context['fieldName'];
$rootType = $context['rootType'];
return function (?Sortable $list, array $args, array $context, ResolveInfo $info) use ($fieldName, $rootType) {
return function (?SS_List $list, array $args, array $context, ResolveInfo $info) use ($fieldName, $rootType) {
if ($list === null) {
return null;
}
Expand Down
Loading

0 comments on commit ee9b3f8

Please sign in to comment.