-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphql):
@sortBy
nulls ordering operators nullsFirst
/`nulls…
…Last` (#119)
- Loading branch information
Showing
23 changed files
with
892 additions
and
46 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,36 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Builder; | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\Builder\Context; | ||
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[CoversClass(Context::class)] | ||
class ContextTest extends TestCase { | ||
public function testContext(): void { | ||
$context = new Context(); | ||
$class = (new class('origin') { | ||
public function __construct( | ||
public readonly string $value, | ||
) { | ||
// empty | ||
} | ||
})::class; | ||
|
||
self::assertFalse($context->has($class)); | ||
self::assertNull($context->get($class)); | ||
|
||
$overridden = $context->override([$class => new $class('overridden')]); | ||
|
||
self::assertNotSame($context, $overridden); | ||
self::assertFalse($context->has($class)); | ||
self::assertNull($context->get($class)); | ||
self::assertTrue($overridden->has($class)); | ||
self::assertNotNull($overridden->get($class)); | ||
self::assertEquals('overridden', $overridden->get($class)->value); | ||
} | ||
} |
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,51 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace LastDragon_ru\LaraASP\GraphQL\Builder\Traits; | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context; | ||
use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Handler; | ||
use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionEmpty; | ||
use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionTooManyOperators; | ||
use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\HandlerInvalidConditions; | ||
use LastDragon_ru\LaraASP\GraphQL\Builder\Property; | ||
use LastDragon_ru\LaraASP\GraphQL\Utils\ArgumentFactory; | ||
use Nuwave\Lighthouse\Execution\Arguments\Argument; | ||
use Nuwave\Lighthouse\Execution\Arguments\ArgumentSet; | ||
|
||
use function count; | ||
|
||
trait PropertyOperator { | ||
/** | ||
* @template TBuilder of object | ||
* | ||
* @param TBuilder $builder | ||
* | ||
* @return TBuilder | ||
*/ | ||
protected function handle( | ||
Handler $handler, | ||
object $builder, | ||
Property $property, | ||
Argument $argument, | ||
Context $context, | ||
): object { | ||
if (!($argument->value instanceof ArgumentSet)) { | ||
throw new HandlerInvalidConditions($handler); | ||
} | ||
|
||
// Empty? | ||
if (count($argument->value->arguments) === 0) { | ||
throw new ConditionEmpty(); | ||
} | ||
|
||
// Valid? | ||
if (count($argument->value->arguments) > 1) { | ||
throw new ConditionTooManyOperators( | ||
ArgumentFactory::getArgumentsNames($argument->value), | ||
); | ||
} | ||
|
||
// Apply | ||
return $handler->handle($builder, $property, $argument->value, $context); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/graphql/src/SortBy/Definitions/SortByOperatorNullsFirstDirective.php
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,11 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions; | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\SortBy\Operators\Extra\NullsFirst; | ||
|
||
class SortByOperatorNullsFirstDirective extends NullsFirst { | ||
// Lighthouse loads all classes from directive namespace this leads to | ||
// 'Class "Orchestra\Testbench\TestCase" not found' error for our *Test | ||
// classes. This class required to avoid this error. | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/graphql/src/SortBy/Definitions/SortByOperatorNullsLastDirective.php
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,11 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Definitions; | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\SortBy\Operators\Extra\NullsLast; | ||
|
||
class SortByOperatorNullsLastDirective extends NullsLast { | ||
// Lighthouse loads all classes from directive namespace this leads to | ||
// 'Class "Orchestra\Testbench\TestCase" not found' error for our *Test | ||
// classes. This class required to avoid this error. | ||
} |
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
Oops, something went wrong.