|
4 | 4 |
|
5 | 5 | namespace Overblog\GraphQLBundle\Tests\Transformer; |
6 | 6 |
|
| 7 | +use Generator; |
7 | 8 | use GraphQL\Type\Definition\EnumType; |
8 | 9 | use GraphQL\Type\Definition\InputObjectType; |
| 10 | +use GraphQL\Type\Definition\ListOfType; |
| 11 | +use GraphQL\Type\Definition\NonNull; |
9 | 12 | use GraphQL\Type\Definition\ResolveInfo; |
10 | 13 | use GraphQL\Type\Definition\Type; |
11 | 14 | use GraphQL\Type\Schema; |
@@ -294,4 +297,75 @@ public function testRaisedErrorsForMultipleInputs(): void |
294 | 297 | $this->assertEquals($e->toState(), $expected); |
295 | 298 | } |
296 | 299 | } |
| 300 | + |
| 301 | + public function getWrappedInputObject(): Generator |
| 302 | + { |
| 303 | + $inputObject = new InputObjectType([ |
| 304 | + 'name' => 'InputType1', |
| 305 | + 'fields' => [ |
| 306 | + 'field1' => Type::string(), |
| 307 | + 'field2' => Type::int(), |
| 308 | + 'field3' => Type::boolean(), |
| 309 | + ], |
| 310 | + ]); |
| 311 | + yield [$inputObject, false]; |
| 312 | + yield [new NonNull($inputObject), false]; |
| 313 | + } |
| 314 | + |
| 315 | + /** @dataProvider getWrappedInputObject */ |
| 316 | + public function testInputObjectWithWrappingType(Type $type): void |
| 317 | + { |
| 318 | + $transformer = $this->getTransformer([ |
| 319 | + 'InputType1' => ['type' => 'input', 'class' => InputType1::class], |
| 320 | + ], new ConstraintViolationList() |
| 321 | + ); |
| 322 | + $info = $this->getResolveInfo(self::getTypes()); |
| 323 | + |
| 324 | + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; |
| 325 | + |
| 326 | + $inputValue = $transformer->getInstanceAndValidate($type->toString(), $data, $info, 'input1'); |
| 327 | + |
| 328 | + /* @var InputType1 $inputValue */ |
| 329 | + $this->assertInstanceOf(InputType1::class, $inputValue); |
| 330 | + $this->assertEquals($inputValue->field1, $data['field1']); |
| 331 | + $this->assertEquals($inputValue->field2, $data['field2']); |
| 332 | + $this->assertEquals($inputValue->field3, $data['field3']); |
| 333 | + } |
| 334 | + |
| 335 | + public function getWrappedInputObjectList(): Generator |
| 336 | + { |
| 337 | + $inputObject = new InputObjectType([ |
| 338 | + 'name' => 'InputType1', |
| 339 | + 'fields' => [ |
| 340 | + 'field1' => Type::string(), |
| 341 | + 'field2' => Type::int(), |
| 342 | + 'field3' => Type::boolean(), |
| 343 | + ], |
| 344 | + ]); |
| 345 | + yield [new ListOfType($inputObject)]; |
| 346 | + yield [new ListOfType(new NonNull($inputObject))]; |
| 347 | + yield [new NonNull(new ListOfType($inputObject))]; |
| 348 | + yield [new NonNull(new ListOfType(new NonNull($inputObject)))]; |
| 349 | + } |
| 350 | + |
| 351 | + /** @dataProvider getWrappedInputObjectList */ |
| 352 | + public function testInputObjectWithWrappingTypeList(Type $type): void |
| 353 | + { |
| 354 | + $transformer = $this->getTransformer( |
| 355 | + ['InputType1' => ['type' => 'input', 'class' => InputType1::class]], |
| 356 | + new ConstraintViolationList() |
| 357 | + ); |
| 358 | + $info = $this->getResolveInfo(self::getTypes()); |
| 359 | + |
| 360 | + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; |
| 361 | + |
| 362 | + $inputValue = $transformer->getInstanceAndValidate($type->toString(), [$data], $info, 'input1'); |
| 363 | + $inputValue = \reset($inputValue); |
| 364 | + |
| 365 | + /* @var InputType1 $inputValue */ |
| 366 | + $this->assertInstanceOf(InputType1::class, $inputValue); |
| 367 | + $this->assertEquals($inputValue->field1, $data['field1']); |
| 368 | + $this->assertEquals($inputValue->field2, $data['field2']); |
| 369 | + $this->assertEquals($inputValue->field3, $data['field3']); |
| 370 | + } |
297 | 371 | } |
0 commit comments