|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2015–2018 Alexandr Viniychuk <http://youshido.com>. |
|
4
|
|
|
* Copyright (c) 2015–2018 Portey Vasil <https://github.com/portey>. |
|
5
|
|
|
* Copyright (c) 2018 Ryan Parman <https://github.com/skyzyx>. |
|
6
|
|
|
* Copyright (c) 2018 Ashley Hutson <https://github.com/asheliahut>. |
|
7
|
|
|
* Copyright (c) 2015–2018 Contributors. |
|
8
|
|
|
* |
|
9
|
|
|
* http://opensource.org/licenses/MIT |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
/** |
|
14
|
|
|
* Date: 13.05.16. |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace Youshido\GraphQL\Field; |
|
18
|
|
|
|
|
19
|
|
|
use Youshido\GraphQL\Config\Field\FieldConfig; |
|
20
|
|
|
use Youshido\GraphQL\Config\Traits\ResolvableObjectTrait; |
|
21
|
|
|
use Youshido\GraphQL\Type\AbstractType; |
|
22
|
|
|
use Youshido\GraphQL\Type\Object\AbstractObjectType; |
|
23
|
|
|
use Youshido\GraphQL\Type\Traits\AutoNameTrait; |
|
24
|
|
|
use Youshido\GraphQL\Type\Traits\FieldsArgumentsAwareObjectTrait; |
|
25
|
|
|
use Youshido\GraphQL\Type\TypeFactory; |
|
26
|
|
|
use Youshido\GraphQL\Type\TypeService; |
|
27
|
|
|
|
|
28
|
|
|
abstract class AbstractField implements FieldInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use FieldsArgumentsAwareObjectTrait; |
|
31
|
102 |
|
use ResolvableObjectTrait; |
|
32
|
|
|
use AutoNameTrait { |
|
33
|
102 |
|
getName as getAutoName; |
|
34
|
75 |
|
} |
|
35
|
75 |
|
|
|
36
|
75 |
|
protected $isFinal = false; |
|
37
|
2 |
|
|
|
38
|
|
|
private $nameCache; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct(array $config = []) |
|
41
|
102 |
|
{ |
|
42
|
94 |
|
if (empty($config['type'])) { |
|
43
|
|
|
$config['type'] = $this->getType(); |
|
44
|
102 |
|
$config['name'] = $this->getName(); |
|
45
|
|
|
|
|
46
|
102 |
|
if (empty($config['name'])) { |
|
47
|
102 |
|
$config['name'] = $this->getAutoName(); |
|
48
|
102 |
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (TypeService::isScalarType($config['type'])) { |
|
52
|
|
|
$config['type'] = TypeFactory::getScalarType($config['type']); |
|
53
|
|
|
} |
|
54
|
|
|
$this->nameCache = $config['name'] ?? $this->getAutoName(); |
|
55
|
101 |
|
|
|
56
|
|
|
$this->config = new FieldConfig($config, $this, $this->isFinal); |
|
57
|
101 |
|
$this->build($this->config); |
|
58
|
|
|
} |
|
59
|
1 |
|
|
|
60
|
|
|
/** |
|
61
|
1 |
|
* @return AbstractObjectType|AbstractType |
|
62
|
1 |
|
*/ |
|
63
|
|
|
abstract public function getType(); |
|
64
|
2 |
|
|
|
65
|
|
|
public function build(FieldConfig $config): void |
|
66
|
2 |
|
{ |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
5 |
|
public function setType($type): void |
|
70
|
|
|
{ |
|
71
|
5 |
|
$this->getConfig()->set('type', $type); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
5 |
|
public function getName() |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
5 |
|
return $this->nameCache; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function isDeprecated() |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
return $this->getConfigValue('isDeprecated', false); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getDeprecationReason() |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
return $this->getConfigValue('deprecationReason'); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.