|
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\Definition\Builder; |
|
13
|
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\Type; |
|
15
|
|
|
use Overblog\GraphQLBundle\Resolver\ResolverInterface; |
|
16
|
|
|
|
|
17
|
|
|
class TypeBuilder |
|
18
|
|
|
{ |
|
19
|
|
|
private $configResolver; |
|
20
|
|
|
|
|
21
|
|
|
private $mapping = [ |
|
22
|
|
|
'relay-connection' => 'Overblog\\GraphQLBundle\\Relay\\Connection\\ConnectionType', |
|
23
|
|
|
'relay-node' => 'Overblog\\GraphQLBundle\\Relay\\Node\\NodeInterfaceType', |
|
24
|
|
|
'relay-mutation-input' => 'Overblog\\GraphQLBundle\\Relay\\Mutation\\InputType', |
|
25
|
|
|
'relay-mutation-payload' => 'Overblog\\GraphQLBundle\\Relay\\Mutation\\PayloadType', |
|
26
|
|
|
'object' => 'GraphQL\\Type\\Definition\\ObjectType', |
|
27
|
|
|
'enum' => 'GraphQL\\Type\\Definition\\EnumType', |
|
28
|
|
|
'interface' => 'GraphQL\\Type\\Definition\\InterfaceType', |
|
29
|
|
|
'union' => 'GraphQL\\Type\\Definition\\UnionType', |
|
30
|
|
|
'input-object' => 'GraphQL\\Type\\Definition\\InputObjectType', |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
32 |
|
public function __construct(ResolverInterface $configResolver) |
|
34
|
|
|
{ |
|
35
|
32 |
|
$this->configResolver = $configResolver; |
|
36
|
32 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param $type |
|
40
|
|
|
* @param array $config |
|
41
|
|
|
* |
|
42
|
|
|
* @return Type |
|
43
|
|
|
*/ |
|
44
|
32 |
|
public function create($type, array $config) |
|
45
|
|
|
{ |
|
46
|
32 |
|
$class = $this->getBaseClassName($type); |
|
47
|
|
|
|
|
48
|
31 |
|
return new $class($this->configResolver->resolve($config)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
32 |
|
private function getBaseClassName($type) |
|
52
|
|
|
{ |
|
53
|
32 |
|
if (!isset($this->mapping[$type])) { |
|
54
|
1 |
|
throw new \RuntimeException(sprintf('Type "%s" is not managed.', $type)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
31 |
|
return $this->mapping[$type]; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|