-
Notifications
You must be signed in to change notification settings - Fork 1
/
HandlerOperator.php
59 lines (52 loc) · 1.59 KB
/
HandlerOperator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?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\Contracts\Operator;
use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\Client\ConditionEmpty;
use LastDragon_ru\LaraASP\GraphQL\Builder\Exceptions\HandlerInvalidConditions;
use LastDragon_ru\LaraASP\GraphQL\Builder\Field;
use Nuwave\Lighthouse\Execution\Arguments\Argument;
use Nuwave\Lighthouse\Execution\Arguments\ArgumentSet;
use Override;
use function count;
/**
* @phpstan-require-implements Operator
*/
trait HandlerOperator {
#[Override]
public function call(
Handler $handler,
object $builder,
Field $field,
Argument $argument,
Context $context,
): object {
return $this->handle($handler, $builder, $field, $argument, $context);
}
/**
* @template TBuilder of object
*
* @param TBuilder $builder
*
* @return TBuilder
*/
private function handle(
Handler $handler,
object $builder,
Field $field,
Argument $argument,
Context $context,
): object {
// Valid?
if (!($argument->value instanceof ArgumentSet)) {
throw new HandlerInvalidConditions($handler);
}
// Empty?
if (count($argument->value->arguments) === 0) {
throw new ConditionEmpty();
}
// Apply
return $handler->handle($builder, $field, $argument->value, $context);
}
}