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
|
|
|
public function __construct(array $config) |
30
|
|
|
{ |
31
|
|
|
Utils::invariant(!empty($config['name']), 'Every type is expected to have name'); |
32
|
|
|
|
33
|
|
|
Config::validate($config, [ |
34
|
|
|
'name' => Config::STRING | Config::REQUIRED, |
35
|
|
|
'fields' => Config::arrayOf( |
36
|
|
|
FieldDefinition::getDefinition(), |
37
|
|
|
Config::KEY_AS_NAME | Config::MAYBE_THUNK |
38
|
|
|
), |
39
|
|
|
'description' => Config::STRING, |
40
|
|
|
'interfaces' => Config::arrayOf( |
41
|
|
|
Config::INTERFACE_TYPE, |
42
|
|
|
Config::MAYBE_THUNK |
43
|
|
|
), |
44
|
|
|
'isTypeOf' => Config::CALLBACK, // ($value, ResolveInfo $info) => boolean |
|
|
|
|
45
|
|
|
'resolveField' => Config::CALLBACK, |
46
|
|
|
]); |
47
|
|
|
|
48
|
|
|
$this->name = $config['name']; |
49
|
|
|
$this->description = isset($config['description']) ? $config['description'] : null; |
50
|
|
|
$this->resolveFieldFn = isset($config['resolveField']) ? $config['resolveField'] : null; |
51
|
|
|
$this->_isTypeOf = isset($config['isTypeOf']) ? $config['isTypeOf'] : null; |
52
|
|
|
$this->config = $config; |
53
|
|
|
|
54
|
|
|
if (isset($config['interfaces'])) { |
55
|
|
|
InterfaceType::addImplementationToInterfaces($this); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|