|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace TheCodingMachine\GraphQL\Controllers\Annotations; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* SourceFields are fields that are directly source from the base object into GraphQL. |
|
8
|
|
|
* |
|
9
|
|
|
* @Annotation |
|
10
|
|
|
* @Target({"CLASS"}) |
|
11
|
|
|
* @Attributes({ |
|
12
|
|
|
* @Attribute("name", type = "string"), |
|
13
|
|
|
* @Attribute("logged", type = "bool"), |
|
14
|
|
|
* @Attribute("right", type = "TheCodingMachine\GraphQL\Controllers\Annotations\Right"), |
|
15
|
|
|
* @Attribute("returnType", type = "string"), |
|
16
|
|
|
* @Attribute("isId", type = "bool"), |
|
17
|
|
|
* }) |
|
18
|
|
|
*/ |
|
19
|
|
|
class SourceField implements SourceFieldInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Right|null |
|
23
|
|
|
*/ |
|
24
|
|
|
private $right; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string|null |
|
28
|
|
|
*/ |
|
29
|
|
|
private $name; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var bool |
|
33
|
|
|
*/ |
|
34
|
|
|
private $logged; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string|null |
|
38
|
|
|
*/ |
|
39
|
|
|
private $returnType; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var bool |
|
43
|
|
|
*/ |
|
44
|
|
|
private $id; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param mixed[] $attributes |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct(array $attributes = []) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->name = $attributes['name'] ?? null; |
|
52
|
|
|
$this->logged = $attributes['logged'] ?? false; |
|
53
|
|
|
$this->right = $attributes['right'] ?? null; |
|
54
|
|
|
$this->returnType = $attributes['returnType'] ?? null; |
|
55
|
|
|
$this->id = $attributes['isId'] ?? false; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the GraphQL right to be applied to this source field. |
|
60
|
|
|
* |
|
61
|
|
|
* @return Right|null |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getRight(): ?Right |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->right; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the name of the GraphQL query/mutation/field. |
|
70
|
|
|
* If not specified, the name of the method should be used instead. |
|
71
|
|
|
* |
|
72
|
|
|
* @return null|string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getName(): ?string |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->name; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public function isLogged(): bool |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->logged; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns the GraphQL return type of the request (as a string). |
|
89
|
|
|
* The string can represent the FQCN of the type or an entry in the container resolving to the GraphQL type. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string|null |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getReturnType(): ?string |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->returnType; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* If the GraphQL type is "ID", isID will return true. |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
|
|
public function isId(): bool |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->id; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|