-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Standardise OperationResolver::resolve() (#28)
API PaginatedQueryCreator is abstract PSR2 cleanup PHPDoc cleanup
- Loading branch information
Damian Mooyman
authored and
Uncle Cheese
committed
Jan 20, 2017
1 parent
4de64d7
commit eb35ad4
Showing
6 changed files
with
169 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace SilverStripe\GraphQL\Pagination; | ||
|
||
use SilverStripe\Core\Object; | ||
use GraphQL\Type\Definition\EnumType; | ||
use GraphQL\Type\Definition\ObjectType; | ||
|
||
class SortDirectionType extends Object | ||
{ | ||
/** | ||
* @var ObjectType | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @return ObjectType | ||
*/ | ||
public function toType() | ||
{ | ||
if (!$this->type) { | ||
$this->type = new EnumType([ | ||
'name' => 'SortDirection', | ||
'description' => 'Set order order to either ASC or DESC', | ||
'values' => [ | ||
'ASC' => [ | ||
'value' => 'ASC', | ||
'description' => 'Lowest value to highest.' | ||
], | ||
'DESC' => [ | ||
'value' => 'DESC', | ||
'description' => 'Highest value to lowest.' | ||
] | ||
] | ||
]); | ||
} | ||
|
||
return $this->type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace SilverStripe\GraphQL\Pagination; | ||
|
||
use GraphQL\Type\Definition\Type; | ||
use GraphQL\Type\Definition\InputObjectType; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Core\Injector\Injectable; | ||
use GraphQL\Type\Definition\EnumType; | ||
|
||
class SortInputType | ||
{ | ||
use Injectable; | ||
|
||
/** | ||
* @var InputObjectType | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $inputName; | ||
|
||
|
||
/** | ||
* @var array Keyed by field argument name, values as DataObject column names. | ||
* Does not support in-memory sorting for composite values (getters). | ||
*/ | ||
protected $sortableFields = []; | ||
|
||
/** | ||
* | ||
*/ | ||
public function __construct($name) | ||
{ | ||
parent::__construct(); | ||
$this->inputName = $name; | ||
} | ||
|
||
/** | ||
* @param array $sortableFields | ||
* | ||
* @return $this | ||
*/ | ||
public function setSortableFields($sortableFields) | ||
{ | ||
$this->sortableFields = $sortableFields; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Type | ||
*/ | ||
public function toType() | ||
{ | ||
$values = []; | ||
|
||
foreach ($this->sortableFields as $fieldAlias => $fieldName) { | ||
$values[$fieldAlias] = [ | ||
'value' => $fieldAlias | ||
]; | ||
} | ||
|
||
$sortableField = new EnumType([ | ||
'name' => ucfirst($this->inputName) . 'SortFieldType', | ||
'description' => 'Field name to sort by.', | ||
'values' => $values | ||
]); | ||
|
||
if (!$this->type) { | ||
$this->type = new InputObjectType([ | ||
'name' => ucfirst($this->inputName) .'SortInputType', | ||
'description' => 'Define the sorting', | ||
'fields' => [ | ||
'field' => [ | ||
'type' => Type::nonNull($sortableField), | ||
'description' => 'Sort field name.' | ||
], | ||
'direction' => [ | ||
'type' => Injector::inst()->get(SortDirectionType::class)->toType(), | ||
'description' => 'Sort direction (ASC / DESC)' | ||
] | ||
] | ||
]); | ||
} | ||
|
||
return $this->type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters