|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of GraphQL project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 2:29 PM 5/13/16 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\Tests\Library\Field; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Execution\Processor; |
|
13
|
|
|
use Youshido\GraphQL\Field\InputField; |
|
14
|
|
|
use Youshido\GraphQL\Schema\Schema; |
|
15
|
|
|
use Youshido\GraphQL\Type\InputObject\InputObjectType; |
|
16
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
|
17
|
|
|
use Youshido\GraphQL\Type\NonNullType; |
|
18
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
|
19
|
|
|
use Youshido\GraphQL\Type\Scalar\IdType; |
|
20
|
|
|
use Youshido\GraphQL\Type\Scalar\IntType; |
|
21
|
|
|
use Youshido\GraphQL\Type\Scalar\StringType; |
|
22
|
|
|
use Youshido\GraphQL\Validator\ConfigValidator\ConfigValidator; |
|
23
|
|
|
use Youshido\Tests\DataProvider\TestInputField; |
|
24
|
|
|
|
|
25
|
|
|
class InputFieldTest extends \PHPUnit_Framework_TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
private $introspectionQuery = <<<TEXT |
|
29
|
|
|
|
|
30
|
|
|
query IntrospectionQuery { |
|
31
|
|
|
__schema { |
|
32
|
|
|
queryType { name } |
|
33
|
|
|
mutationType { name } |
|
34
|
|
|
types { |
|
35
|
|
|
...FullType |
|
36
|
|
|
} |
|
37
|
|
|
directives { |
|
38
|
|
|
name |
|
39
|
|
|
description |
|
40
|
|
|
args { |
|
41
|
|
|
...InputValue |
|
42
|
|
|
} |
|
43
|
|
|
onOperation |
|
44
|
|
|
onFragment |
|
45
|
|
|
onField |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
fragment FullType on __Type { |
|
51
|
|
|
kind |
|
52
|
|
|
name |
|
53
|
|
|
description |
|
54
|
|
|
fields { |
|
55
|
|
|
name |
|
56
|
|
|
description |
|
57
|
|
|
args { |
|
58
|
|
|
...InputValue |
|
59
|
|
|
} |
|
60
|
|
|
type { |
|
61
|
|
|
...TypeRef |
|
62
|
|
|
} |
|
63
|
|
|
isDeprecated |
|
64
|
|
|
deprecationReason |
|
65
|
|
|
} |
|
66
|
|
|
inputFields { |
|
67
|
|
|
...InputValue |
|
68
|
|
|
} |
|
69
|
|
|
interfaces { |
|
70
|
|
|
...TypeRef |
|
71
|
|
|
} |
|
72
|
|
|
enumValues { |
|
73
|
|
|
name |
|
74
|
|
|
description |
|
75
|
|
|
isDeprecated |
|
76
|
|
|
deprecationReason |
|
77
|
|
|
} |
|
78
|
|
|
possibleTypes { |
|
79
|
|
|
...TypeRef |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
fragment InputValue on __InputValue { |
|
84
|
|
|
name |
|
85
|
|
|
description |
|
86
|
|
|
type { ...TypeRef } |
|
87
|
|
|
defaultValue |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
fragment TypeRef on __Type { |
|
91
|
|
|
kind |
|
92
|
|
|
name |
|
93
|
|
|
ofType { |
|
94
|
|
|
kind |
|
95
|
|
|
name |
|
96
|
|
|
ofType { |
|
97
|
|
|
kind |
|
98
|
|
|
name |
|
99
|
|
|
ofType { |
|
100
|
|
|
kind |
|
101
|
|
|
name |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
TEXT; |
|
107
|
|
|
|
|
108
|
|
|
public function testFieldWithInputFieldArgument() |
|
109
|
|
|
{ |
|
110
|
|
|
$schema = new Schema([ |
|
111
|
|
|
'query' => new ObjectType([ |
|
112
|
|
|
'name' => 'RootQuery', |
|
113
|
|
|
'fields' => [ |
|
114
|
|
|
'amount' => [ |
|
115
|
|
|
'type' => new IntType(), |
|
116
|
|
|
'args' => [ |
|
117
|
|
|
new InputField([ |
|
118
|
|
|
'name' => 'input', |
|
119
|
|
|
'type' => new InputObjectType([ |
|
120
|
|
|
'name' => 'TestInput', |
|
121
|
|
|
'fields' => [ |
|
122
|
|
|
new InputField(['name' => 'clientMutationId', 'type' => new NonNullType(new StringType())]) |
|
123
|
|
|
] |
|
124
|
|
|
]) |
|
125
|
|
|
]) |
|
126
|
|
|
], |
|
127
|
|
|
] |
|
128
|
|
|
|
|
129
|
|
|
] |
|
130
|
|
|
]) |
|
131
|
|
|
]); |
|
132
|
|
|
$processor = new Processor($schema); |
|
133
|
|
|
$processor->processPayload($this->introspectionQuery); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function testInlineInputFieldCreation() |
|
137
|
|
|
{ |
|
138
|
|
|
$field = new InputField([ |
|
139
|
|
|
'name' => 'id', |
|
140
|
|
|
'type' => 'id', |
|
141
|
|
|
'description' => 'description', |
|
142
|
|
|
'defaultValue' => 123 |
|
143
|
|
|
]); |
|
144
|
|
|
|
|
145
|
|
|
$this->assertEquals('id', $field->getName()); |
|
146
|
|
|
$this->assertEquals(new IdType(), $field->getType()); |
|
147
|
|
|
$this->assertEquals('description', $field->getDescription()); |
|
148
|
|
|
$this->assertSame(123, $field->getDefaultValue()); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
public function testObjectInputFieldCreation() |
|
153
|
|
|
{ |
|
154
|
|
|
$field = new TestInputField(); |
|
155
|
|
|
|
|
156
|
|
|
$this->assertEquals('testInput', $field->getName()); |
|
157
|
|
|
$this->assertEquals('description', $field->getDescription()); |
|
158
|
|
|
$this->assertEquals(new IntType(), $field->getType()); |
|
159
|
|
|
$this->assertEquals('default', $field->getDefaultValue()); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function testListAsInputField() |
|
163
|
|
|
{ |
|
164
|
|
|
new InputField([ |
|
165
|
|
|
'name' => 'test', |
|
166
|
|
|
'type' => new ListType(new IntType()), |
|
167
|
|
|
]); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @dataProvider invalidInputFieldProvider |
|
172
|
|
|
* @expectedException Youshido\GraphQL\Exception\ConfigurationException |
|
173
|
|
|
*/ |
|
174
|
|
|
public function testInvalidInputFieldParams($fieldConfig) |
|
175
|
|
|
{ |
|
176
|
|
|
$field = new InputField($fieldConfig); |
|
177
|
|
|
ConfigValidator::getInstance()->assertValidConfig($field->getConfig()); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function invalidInputFieldProvider() |
|
181
|
|
|
{ |
|
182
|
|
|
return [ |
|
183
|
|
|
[ |
|
184
|
|
|
[ |
|
185
|
|
|
'name' => 'id', |
|
186
|
|
|
'type' => 'invalid type' |
|
187
|
|
|
] |
|
188
|
|
|
], |
|
189
|
|
|
[ |
|
190
|
|
|
[ |
|
191
|
|
|
'name' => 'id', |
|
192
|
|
|
'type' => new ObjectType([ |
|
193
|
|
|
'name' => 'test', |
|
194
|
|
|
'fields' => [ |
|
195
|
|
|
'id' => ['type' => 'int'] |
|
196
|
|
|
] |
|
197
|
|
|
]) |
|
198
|
|
|
] |
|
199
|
|
|
], |
|
200
|
|
|
]; |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|