Skip to content

[WIP] Feature/sort priority #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 12.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
}
],
"require": {
"php": "^8.1",
"doctrine/orm": "^2.18 || ^3.0",
"php": "^8.3",
"doctrine/orm": "^3.0",
"doctrine/doctrine-laminas-hydrator": "^3.2",
"webonyx/graphql-php": "^v15.0",
"psr/container": "^1.1 || ^2.0",
"psr/container": "^2.0",
"league/event": "^3.0"
},
"require-dev": {
"doctrine/coding-standard": "^11.0 || ^12.0",
"doctrine/coding-standard": "^13.0",
"doctrine/dbal": "^3.1 || ^4.0",
"phpunit/phpunit": "^9.6",
"vimeo/psalm": "^5.4",
"vimeo/psalm": "^6.13",
"symfony/cache": "^5.3||^6.2",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpstan/phpstan": "^1.12 || ^2.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/driver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Creating a Driver with all config options
use ApiSkeletons\Doctrine\ORM\GraphQL\Driver;
use ApiSkeletons\Doctrine\ORM\GraphQL\Filter\Filters;

$driver = new Driver($entityManager, new Config[
$driver = new Driver($entityManager, new Config([
'entityPrefix' => 'App\\ORM\\Entity\\',
'group' => 'customGroup',
'groupSuffix' => 'customGroupSuffix',
Expand Down
3 changes: 3 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Closure;
use GraphQL\Error\Error;
use Override;
use Psr\Container\ContainerInterface;
use ReflectionClass;
use ReflectionException;
Expand All @@ -21,12 +22,14 @@ abstract class Container implements ContainerInterface
/** @var mixed[] */
protected array $register = [];

#[Override]
public function has(string $id): bool
{
return isset($this->register[strtolower($id)]);
}

/** @throws Error */
#[Override]
public function get(string $id): mixed
{
$id = strtolower($id);
Expand Down
2 changes: 2 additions & 0 deletions src/Event/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\ORM\PersistentCollection;
use GraphQL\Type\Definition\ResolveInfo;
use League\Event\HasEventName;
use Override;

/**
* This event is dispatched when a Doctrine Criteria is created.
Expand All @@ -34,6 +35,7 @@ public function __construct(
) {
}

#[Override]
public function eventName(): string
{
return $this->eventName;
Expand Down
2 changes: 2 additions & 0 deletions src/Event/EntityDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ArrayObject;
use League\Event\HasEventName;
use Override;

/**
* This event is fired each time an entity GraphQL type is created
Expand All @@ -20,6 +21,7 @@ public function __construct(
) {
}

#[Override]
public function eventName(): string
{
return $this->eventName;
Expand Down
2 changes: 2 additions & 0 deletions src/Event/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ArrayObject;
use League\Event\HasEventName;
use Override;

/**
* This event is fired when the metadta is created
Expand All @@ -19,6 +20,7 @@ public function __construct(
) {
}

#[Override]
public function eventName(): string
{
return $this->eventName;
Expand Down
2 changes: 2 additions & 0 deletions src/Event/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ORM\QueryBuilder as DoctrineQueryBuilder;
use GraphQL\Type\Definition\ResolveInfo;
use League\Event\HasEventName;
use Override;

/**
* This event is fired when the QueryBuilder is created for an entity
Expand All @@ -27,6 +28,7 @@ public function __construct(
) {
}

#[Override]
public function eventName(): string
{
return $this->eventName;
Expand Down
87 changes: 45 additions & 42 deletions src/Filter/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,43 @@
*/
enum Filters: string
{
case EQ = 'eq';
case NEQ = 'neq';
case LT = 'lt';
case LTE = 'lte';
case GT = 'gt';
case GTE = 'gte';
case BETWEEN = 'between';
case CONTAINS = 'contains';
case STARTSWITH = 'startswith';
case ENDSWITH = 'endswith';
case IN = 'in';
case NOTIN = 'notin';
case ISNULL = 'isnull';
case SORT = 'sort';
case EQ = 'eq';
case NEQ = 'neq';
case LT = 'lt';
case LTE = 'lte';
case GT = 'gt';
case GTE = 'gte';
case BETWEEN = 'between';
case CONTAINS = 'contains';
case STARTSWITH = 'startswith';
case ENDSWITH = 'endswith';
case IN = 'in';
case NOTIN = 'notin';
case ISNULL = 'isnull';
case SORT = 'sort';
case SORTPRIORITY = 'sortPriority';

/**
* Fetch the description for the filter
*/
public function description(): string
{
return match ($this) {
self::EQ => 'Equals',
self::NEQ => 'Not equals',
self::LT => 'Less than',
self::LTE => 'Less than or equals',
self::GT => 'Greater than',
self::GTE => 'Greater than or equals',
self::BETWEEN => 'Is between from and to inclusive of from and to',
self::CONTAINS => 'Contains the value. Strings only.',
self::STARTSWITH => 'Starts with the value. Strings only.',
self::ENDSWITH => 'Ends with the value. Strings only.',
self::IN => 'In the array of values',
self::NOTIN => 'Not in the array of values',
self::ISNULL => 'Is null',
self::SORT => 'Sort by field. ASC or DESC.',
self::EQ => 'Equals',
self::NEQ => 'Not equals',
self::LT => 'Less than',
self::LTE => 'Less than or equals',
self::GT => 'Greater than',
self::GTE => 'Greater than or equals',
self::BETWEEN => 'Is between from and to inclusive of from and to',
self::CONTAINS => 'Contains the value. Strings only.',
self::STARTSWITH => 'Starts with the value. Strings only.',
self::ENDSWITH => 'Ends with the value. Strings only.',
self::IN => 'In the array of values',
self::NOTIN => 'Not in the array of values',
self::ISNULL => 'Is null',
self::SORT => 'Sort by field. ASC or DESC.',
self::SORTPRIORITY => 'Specify the sort priority of a field. Priorities are sorted lowest number first. Sort must also be speciifed.',
};
}

Expand All @@ -61,20 +63,21 @@ public function description(): string
public function type(ScalarType|ListOfType $type): Type
{
return match ($this) {
self::EQ => $type,
self::NEQ => $type,
self::LT => $type,
self::LTE => $type,
self::GT => $type,
self::GTE => $type,
self::BETWEEN => new Between($type),
self::CONTAINS => $type,
self::STARTSWITH => $type,
self::ENDSWITH => $type,
self::IN => Type::listOf($type),
self::NOTIN => Type::listOf($type),
self::ISNULL => Type::boolean(),
self::SORT => Type::string(),
self::EQ => $type,
self::NEQ => $type,
self::LT => $type,
self::LTE => $type,
self::GT => $type,
self::GTE => $type,
self::BETWEEN => new Between($type),
self::CONTAINS => $type,
self::STARTSWITH => $type,
self::ENDSWITH => $type,
self::IN => Type::listOf($type),
self::NOTIN => Type::listOf($type),
self::ISNULL => Type::boolean(),
self::SORT => Type::string(),
self::SORTPRIORITY => Type::int(),
};
}

Expand Down
Loading
Loading