|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of graphql-youshido project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 12/2/15 8:57 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\GraphQL\Type\Object; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Type\AbstractType; |
|
13
|
|
|
use Youshido\GraphQL\Type\Config\Object\ObjectTypeConfig; |
|
14
|
|
|
use Youshido\GraphQL\Type\Config\Traits\ConfigCallTrait; |
|
15
|
|
|
use Youshido\GraphQL\Type\Config\TypeConfigInterface; |
|
16
|
|
|
use Youshido\GraphQL\Type\Field\Field; |
|
17
|
|
|
use Youshido\GraphQL\Type\Traits\AutoNameTrait; |
|
18
|
|
|
use Youshido\GraphQL\Type\TypeMap; |
|
19
|
|
|
use Youshido\GraphQL\Validator\Exception\ResolveException; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class AbstractObjectType |
|
23
|
|
|
* @package Youshido\GraphQL\Type\Object |
|
24
|
|
|
* |
|
25
|
|
|
* @method bool hasFields() |
|
26
|
|
|
* @method bool hasField($field) |
|
27
|
|
|
* @method Field getField($field) |
|
28
|
|
|
* @method $this addField($name, $type, $config = []) |
|
29
|
|
|
* @method $this addFields($fields) |
|
30
|
|
|
*/ |
|
31
|
|
|
abstract class AbstractObjectType extends AbstractType |
|
32
|
|
|
{ |
|
33
|
|
|
use ConfigCallTrait, AutoNameTrait; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* ObjectType constructor. |
|
37
|
|
|
* @param $config |
|
38
|
|
|
*/ |
|
39
|
24 |
|
public function __construct($config = []) |
|
40
|
|
|
{ |
|
41
|
24 |
|
if (empty($config)) { |
|
42
|
22 |
|
$config['name'] = $this->getName(); |
|
43
|
22 |
|
$config['interfaces'] = $this->getInterfaces(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
24 |
|
$this->config = new ObjectTypeConfig($config, $this); |
|
47
|
24 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
abstract public function resolve($value = null, $args = [], $type = null); |
|
50
|
|
|
|
|
51
|
|
|
public function parseValue($value) |
|
52
|
|
|
{ |
|
53
|
|
|
return $value; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
final public function serialize($value) |
|
57
|
|
|
{ |
|
58
|
|
|
throw new ResolveException('You can not serialize object value directly'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
22 |
|
public function getKind() |
|
62
|
|
|
{ |
|
63
|
22 |
|
return TypeMap::KIND_OBJECT; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getType() |
|
67
|
|
|
{ |
|
68
|
|
|
$config = $this->getConfig(); |
|
69
|
|
|
return $config && $config->getType() ? $config->getType() : $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return AbstractInterfaceType[] |
|
74
|
|
|
*/ |
|
75
|
22 |
|
public function getInterfaces() |
|
76
|
|
|
{ |
|
77
|
22 |
|
return []; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function isValidValue($value) |
|
81
|
|
|
{ |
|
82
|
|
|
return (get_class($value) == get_class($this)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|