|
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; |
|
13
|
|
|
|
|
14
|
|
|
use GraphQL\Type\Definition\Config; |
|
15
|
|
|
use GraphQL\Type\Definition\ObjectType as BaseObjectType; |
|
16
|
|
|
use GraphQL\Utils; |
|
17
|
|
|
|
|
18
|
|
|
class ObjectType extends BaseObjectType |
|
19
|
|
|
{ |
|
20
|
|
|
use FieldsTrait; |
|
21
|
|
|
|
|
22
|
|
|
private $_isTypeOf; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param array $config |
|
26
|
|
|
* |
|
27
|
|
|
* @todo open PR on lib to ease inheritance |
|
28
|
|
|
*/ |
|
29
|
38 |
|
public function __construct(array $config) |
|
30
|
|
|
{ |
|
31
|
38 |
|
Utils::invariant(!empty($config['name']), 'Every type is expected to have name'); |
|
32
|
|
|
|
|
33
|
38 |
|
Config::validate($config, [ |
|
34
|
38 |
|
'name' => Config::STRING | Config::REQUIRED, |
|
35
|
38 |
|
'fields' => Config::arrayOf( |
|
36
|
38 |
|
FieldDefinition::getDefinition(), |
|
37
|
38 |
|
Config::KEY_AS_NAME | Config::MAYBE_THUNK |
|
38
|
38 |
|
), |
|
39
|
38 |
|
'description' => Config::STRING, |
|
40
|
38 |
|
'interfaces' => Config::arrayOf( |
|
41
|
38 |
|
Config::INTERFACE_TYPE, |
|
42
|
|
|
Config::MAYBE_THUNK |
|
43
|
38 |
|
), |
|
44
|
38 |
|
'isTypeOf' => Config::CALLBACK, // ($value, ResolveInfo $info) => boolean |
|
|
|
|
|
|
45
|
38 |
|
'resolveField' => Config::CALLBACK, |
|
46
|
38 |
|
]); |
|
47
|
|
|
|
|
48
|
38 |
|
$this->name = $config['name']; |
|
49
|
38 |
|
$this->description = isset($config['description']) ? $config['description'] : null; |
|
50
|
38 |
|
$this->resolveFieldFn = isset($config['resolveField']) ? $config['resolveField'] : null; |
|
51
|
38 |
|
$this->_isTypeOf = isset($config['isTypeOf']) ? $config['isTypeOf'] : null; |
|
52
|
38 |
|
$this->config = $config; |
|
53
|
|
|
|
|
54
|
38 |
|
if (isset($config['interfaces'])) { |
|
55
|
11 |
|
InterfaceType::addImplementationToInterfaces($this); |
|
56
|
11 |
|
} |
|
57
|
38 |
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|