|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of GraphQL project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 3:40 PM 4/29/16 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\GraphQL\Type; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Config\Traits\ConfigAwareTrait; |
|
13
|
|
|
use Youshido\GraphQL\Exception\ConfigurationException; |
|
14
|
|
|
|
|
15
|
|
|
final class NonNullType extends AbstractType implements CompositeTypeInterface |
|
16
|
|
|
{ |
|
17
|
|
|
use ConfigAwareTrait; |
|
18
|
|
|
|
|
19
|
|
|
private $_typeOf; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* NonNullType constructor. |
|
23
|
|
|
* |
|
24
|
|
|
* @param AbstractType|string $fieldType |
|
25
|
|
|
* |
|
26
|
|
|
* @throws ConfigurationException |
|
27
|
|
|
*/ |
|
28
|
60 |
|
public function __construct($fieldType) |
|
29
|
|
|
{ |
|
30
|
60 |
|
if (!TypeService::isGraphQLType($fieldType)) { |
|
31
|
1 |
|
throw new ConfigurationException('NonNullType accepts only GraphpQL Types as argument'); |
|
32
|
|
|
} |
|
33
|
59 |
|
if (TypeService::isScalarType($fieldType)) { |
|
34
|
59 |
|
$fieldType = TypeFactory::getScalarType($fieldType); |
|
|
|
|
|
|
35
|
59 |
|
} |
|
36
|
|
|
|
|
37
|
59 |
|
$this->_typeOf = $fieldType; |
|
38
|
59 |
|
} |
|
39
|
|
|
|
|
40
|
8 |
|
public function getName() |
|
41
|
|
|
{ |
|
42
|
8 |
|
return null; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
32 |
|
public function getKind() |
|
46
|
|
|
{ |
|
47
|
32 |
|
return TypeMap::KIND_NON_NULL; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function resolve($value) |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $value; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
16 |
|
public function isValidValue($value) |
|
56
|
|
|
{ |
|
57
|
16 |
|
if ($value === null) { |
|
58
|
7 |
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
15 |
|
return $this->getNullableType()->isValidValue($value); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
9 |
|
public function isCompositeType() |
|
65
|
|
|
{ |
|
66
|
9 |
|
return true; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
7 |
|
public function isInputType() |
|
70
|
|
|
{ |
|
71
|
7 |
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
15 |
|
public function getNamedType() |
|
75
|
|
|
{ |
|
76
|
15 |
|
return $this->getTypeOf(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
29 |
|
public function getNullableType() |
|
80
|
|
|
{ |
|
81
|
29 |
|
return $this->getTypeOf(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
32 |
|
public function getTypeOf() |
|
85
|
|
|
{ |
|
86
|
32 |
|
return $this->_typeOf; |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
5 |
|
public function parseValue($value) |
|
90
|
|
|
{ |
|
91
|
5 |
|
return $this->getNullableType()->parseValue($value); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.