|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fubhy\GraphQL\Type\Definition; |
|
4
|
|
|
|
|
5
|
|
|
class FieldDefinition |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var string |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $name; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var string|null |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $description; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var callable |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $resolve; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \Fubhy\GraphQL\Type\Definition\Types\OutputTypeInterface|callable |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $type; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $args = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $argMap; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string|null |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $deprecationReason; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $resolveData; |
|
46
|
|
|
|
|
47
|
291 |
|
/** |
|
48
|
|
|
* Constructor. |
|
49
|
291 |
|
* |
|
50
|
291 |
|
* @param array $config |
|
51
|
291 |
|
*/ |
|
52
|
291 |
|
public function __construct(array $config) |
|
53
|
|
|
{ |
|
54
|
291 |
|
$this->name = $config['name']; |
|
55
|
159 |
|
$this->type = $config['type']; |
|
56
|
159 |
|
$this->description = isset($config['description']) ? $config['description'] : NULL; |
|
57
|
|
|
$this->resolve = isset($config['resolve']) ? $config['resolve'] : NULL; |
|
58
|
291 |
|
|
|
59
|
6 |
|
if (isset($config['args'])) { |
|
60
|
6 |
|
$this->args = $config['args']; |
|
61
|
291 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (isset($config['deprecationReason'])) { |
|
64
|
|
|
$this->deprecationReason = $config['deprecationReason']; |
|
65
|
|
|
} |
|
66
|
285 |
|
|
|
67
|
|
|
if (isset($config['resolveData'])) { |
|
68
|
285 |
|
$this->resolveData = $config['resolveData']; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return string |
|
74
|
3 |
|
*/ |
|
75
|
|
|
public function getName() |
|
76
|
3 |
|
{ |
|
77
|
|
|
return $this->name; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string|null |
|
82
|
303 |
|
*/ |
|
83
|
|
|
public function getDescription() |
|
84
|
303 |
|
{ |
|
85
|
207 |
|
return $this->description; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
303 |
|
/** |
|
89
|
|
|
* @return \Fubhy\GraphQL\Type\Definition\Types\OutputTypeInterface |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getType() |
|
92
|
|
|
{ |
|
93
|
|
|
if (is_callable($this->type)) { |
|
94
|
276 |
|
$this->type = call_user_func($this->type); |
|
95
|
|
|
} |
|
96
|
276 |
|
|
|
97
|
|
|
return $this->type; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return callable|null |
|
102
|
24 |
|
*/ |
|
103
|
|
|
public function getResolveCallback() |
|
104
|
24 |
|
{ |
|
105
|
|
|
return $this->resolve; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return mixed |
|
110
|
297 |
|
*/ |
|
111
|
|
|
public function getResolveData() |
|
112
|
297 |
|
{ |
|
113
|
282 |
|
return $this->resolveData; |
|
114
|
282 |
|
} |
|
115
|
156 |
|
|
|
116
|
141 |
|
/** |
|
117
|
141 |
|
* @return string|null |
|
118
|
|
|
*/ |
|
119
|
156 |
|
public function getDeprecationReason() |
|
120
|
282 |
|
{ |
|
121
|
282 |
|
return $this->deprecationReason; |
|
122
|
|
|
} |
|
123
|
297 |
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return \Fubhy\GraphQL\Type\Definition\FieldArgument[] |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getArguments() |
|
128
|
|
|
{ |
|
129
|
|
|
if (!isset($this->argMap)) { |
|
130
|
|
|
$this->argMap = []; |
|
131
|
|
|
foreach ($this->args as $name => $arg) { |
|
132
|
|
|
if (!isset($arg['name'])) { |
|
133
|
|
|
$arg['name'] = $name; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$this->argMap[$name] = new FieldArgument($arg); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $this->argMap; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|