-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathWrapArgumentConfigProcessor.php
52 lines (39 loc) · 1.42 KB
/
WrapArgumentConfigProcessor.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
<?php
declare(strict_types=1);
namespace Overblog\GraphQLBundle\Definition\ConfigProcessor;
use Overblog\GraphQLBundle\Definition\ArgumentFactory;
use function is_array;
use function is_callable;
final class WrapArgumentConfigProcessor implements ConfigProcessorInterface
{
private ArgumentFactory $argumentFactory;
public function __construct(ArgumentFactory $argumentFactory)
{
$this->argumentFactory = $argumentFactory;
}
public function process(array $config): array
{
if (isset($config['resolveField']) && is_callable($config['resolveField'])) {
$config['resolveField'] = $this->argumentFactory->wrapResolverArgs($config['resolveField']);
}
if (isset($config['fields'])) {
$config['fields'] = function () use ($config) {
$fields = $config['fields'];
if (is_callable($config['fields'])) {
$fields = $config['fields']();
}
return $this->wrapFieldsArgument($fields);
};
}
return $config;
}
private function wrapFieldsArgument(array $fields): array
{
foreach ($fields as &$field) {
if (is_array($field) && isset($field['resolve']) && is_callable($field['resolve'])) {
$field['resolve'] = $this->argumentFactory->wrapResolverArgs($field['resolve']);
}
}
return $fields;
}
}