|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Relay\Node; |
|
13
|
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\Config; |
|
15
|
|
|
use GraphQL\Type\Definition\Type; |
|
16
|
|
|
use Overblog\GraphQLBundle\Definition\FieldInterface; |
|
17
|
|
|
|
|
18
|
|
|
class PluralIdentifyingRootField implements FieldInterface |
|
19
|
|
|
{ |
|
20
|
|
|
public function toFieldDefinition(array $config) |
|
21
|
|
|
{ |
|
22
|
|
|
Config::validate($config, [ |
|
23
|
|
|
'name' => Config::STRING, |
|
24
|
|
|
'argName' => Config::STRING | Config::REQUIRED, |
|
25
|
|
|
'inputType' => Config::OBJECT_TYPE | Config::CALLBACK | Config::REQUIRED, |
|
26
|
|
|
'outputType' => Config::OBJECT_TYPE | Config::CALLBACK | Config::REQUIRED, |
|
27
|
|
|
'resolveSingleInput' => Config::CALLBACK | Config::REQUIRED, |
|
28
|
|
|
'description' => Config::STRING, |
|
29
|
|
|
]); |
|
30
|
|
|
|
|
31
|
|
|
$inputArgs = [ |
|
32
|
|
|
$config['argName'] => [ |
|
33
|
|
|
'type' => Type::nonNull( |
|
34
|
|
|
Type::listOf( |
|
35
|
|
|
Type::nonNull($config['inputType']) |
|
36
|
|
|
) |
|
37
|
|
|
), |
|
38
|
|
|
], |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
return [ |
|
42
|
|
|
'name' => $config['name'], |
|
43
|
|
|
'description' => isset($config['description']) ? $config['description'] : null, |
|
44
|
|
|
'type' => Type::listOf($config['outputType']), |
|
45
|
|
|
'args' => $inputArgs, |
|
46
|
|
|
'resolve' => function ($obj, $args, $info) use ($config) { |
|
47
|
|
|
$inputs = $args[$config['argName']]; |
|
48
|
|
|
|
|
49
|
|
|
$data = []; |
|
50
|
|
|
|
|
51
|
|
|
foreach ($inputs as $input) { |
|
52
|
|
|
$data[$input] = is_callable($config['resolveSingleInput']) ? |
|
53
|
|
|
call_user_func_array($config['resolveSingleInput'], [$input, $info]) : |
|
54
|
|
|
null; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $data; |
|
58
|
|
|
}, |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|