1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Digia\GraphQL\Type\Definition; |
4
|
|
|
|
5
|
|
|
use Digia\GraphQL\Error\InvariantException; |
6
|
|
|
use Digia\GraphQL\Language\Node\ASTNodeAwareInterface; |
7
|
|
|
use Digia\GraphQL\Language\Node\ASTNodeTrait; |
8
|
|
|
use Digia\GraphQL\Language\Node\FieldDefinitionNode; |
9
|
|
|
|
10
|
|
|
class Field implements ASTNodeAwareInterface, ArgumentsAwareInterface |
11
|
|
|
{ |
12
|
|
|
use NameTrait; |
13
|
|
|
use DescriptionTrait; |
14
|
|
|
use TypeTrait; |
15
|
|
|
use ArgumentsTrait; |
16
|
|
|
use ResolveTrait; |
17
|
|
|
use DeprecationTrait; |
18
|
|
|
use ASTNodeTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var callable|null |
22
|
|
|
*/ |
23
|
|
|
protected $subscribeCallback; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Field constructor. |
27
|
|
|
* |
28
|
|
|
* @param string $name |
29
|
|
|
* @param null|string $description |
30
|
|
|
* @param TypeInterface|OutputTypeInterface|WrappingTypeInterface|null $type |
31
|
|
|
* @param Argument[]|array[] $arguments |
32
|
|
|
* @param callable|null $resolveCallback |
33
|
|
|
* @param callable|null $subscribeCallback |
34
|
|
|
* @param null|string $deprecationReason |
35
|
|
|
* @param FieldDefinitionNode|null $astNode |
36
|
|
|
* @throws InvariantException |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
string $name, |
40
|
|
|
?string $description, |
41
|
|
|
?TypeInterface $type, |
42
|
|
|
array $arguments, |
43
|
|
|
?callable $resolveCallback, |
44
|
|
|
?callable $subscribeCallback, |
45
|
|
|
?string $deprecationReason, |
46
|
|
|
?FieldDefinitionNode $astNode |
47
|
|
|
) { |
48
|
|
|
$this->name = $name; |
49
|
|
|
$this->description = $description; |
50
|
|
|
$this->type = $type; |
51
|
|
|
$this->resolveCallback = $resolveCallback; |
52
|
|
|
$this->subscribeCallback = $subscribeCallback; |
53
|
|
|
$this->deprecationReason = $deprecationReason; |
54
|
|
|
$this->astNode = $astNode; |
55
|
|
|
|
56
|
|
|
$this->buildArguments($arguments); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array ...$args |
61
|
|
|
* @return mixed |
62
|
|
|
*/ |
63
|
|
|
public function subscribe(...$args) |
64
|
|
|
{ |
65
|
|
|
return null !== $this->subscribeCallback |
66
|
|
|
? \call_user_func_array($this->subscribeCallback, $args) |
67
|
|
|
: null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function hasSubscribeCallback() |
74
|
|
|
{ |
75
|
|
|
return null !== $this->subscribeCallback; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return callable|null |
80
|
|
|
*/ |
81
|
|
|
public function getSubscribeCallback(): ?callable |
82
|
|
|
{ |
83
|
|
|
return $this->subscribeCallback; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|