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