Skip to content

Commit 5f3e157

Browse files
committed
Fix error for non-nullable array of non-nullable elements annotation
1 parent 39957a3 commit 5f3e157

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/Transformer/ArgumentsTransformerTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
namespace Overblog\GraphQLBundle\Tests\Transformer;
66

77
use Exception;
8+
use Generator;
89
use GraphQL\Type\Definition\EnumType;
910
use GraphQL\Type\Definition\InputObjectType;
11+
use GraphQL\Type\Definition\ListOfType;
12+
use GraphQL\Type\Definition\NonNull;
1013
use GraphQL\Type\Definition\ResolveInfo;
1114
use GraphQL\Type\Definition\Type;
1215
use GraphQL\Type\Schema;
@@ -300,4 +303,75 @@ public function testRaisedErrorsForMultipleInputs(): void
300303
$this->assertEquals($e->toState(), $expected);
301304
}
302305
}
306+
307+
public function getWrappedInputObject(): Generator
308+
{
309+
$inputObject = new InputObjectType([
310+
'name' => 'InputType1',
311+
'fields' => [
312+
'field1' => Type::string(),
313+
'field2' => Type::int(),
314+
'field3' => Type::boolean(),
315+
],
316+
]);
317+
yield [$inputObject, false];
318+
yield [new NonNull($inputObject), false];
319+
}
320+
321+
/** @dataProvider getWrappedInputObject */
322+
public function testInputObjectWithWrappingType(Type $type): void
323+
{
324+
$transformer = $this->getTransformer([
325+
'InputType1' => ['type' => 'input', 'class' => InputType1::class],
326+
], new ConstraintViolationList()
327+
);
328+
$info = $this->getResolveInfo(self::getTypes());
329+
330+
$data = ['field1' => 'hello', 'field2' => 12, 'field3' => true];
331+
332+
$inputValue = $transformer->getInstanceAndValidate($type->toString(), $data, $info, 'input1');
333+
334+
/** @var InputType1 $inputValue */
335+
$this->assertInstanceOf(InputType1::class, $inputValue);
336+
$this->assertEquals($inputValue->field1, $data['field1']);
337+
$this->assertEquals($inputValue->field2, $data['field2']);
338+
$this->assertEquals($inputValue->field3, $data['field3']);
339+
}
340+
341+
public function getWrappedInputObjectList(): Generator
342+
{
343+
$inputObject = new InputObjectType([
344+
'name' => 'InputType1',
345+
'fields' => [
346+
'field1' => Type::string(),
347+
'field2' => Type::int(),
348+
'field3' => Type::boolean(),
349+
],
350+
]);
351+
yield [new ListOfType($inputObject)];
352+
yield [new ListOfType(new NonNull($inputObject))];
353+
yield [new NonNull(new ListOfType($inputObject))];
354+
yield [new NonNull(new ListOfType(new NonNull($inputObject)))];
355+
}
356+
357+
/** @dataProvider getWrappedInputObject */
358+
public function testInputObjectWithWrappingTypeList(Type $type): void
359+
{
360+
$transformer = $this->getTransformer(
361+
['InputType1' => ['type' => 'input', 'class' => InputType1::class]],
362+
new ConstraintViolationList()
363+
);
364+
$info = $this->getResolveInfo(self::getTypes());
365+
366+
$data = ['field1' => 'hello', 'field2' => 12, 'field3' => true];
367+
368+
$inputValue = $transformer->getInstanceAndValidate($type->toString(), [$data], $info, 'input1');
369+
$inputValue = reset($inputValue);
370+
371+
/** @var InputType1 $inputValue */
372+
$this->assertInstanceOf(InputType1::class, $inputValue);
373+
$this->assertEquals($inputValue->field1, $data['field1']);
374+
$this->assertEquals($inputValue->field2, $data['field2']);
375+
$this->assertEquals($inputValue->field3, $data['field3']);
376+
}
303377
}

0 commit comments

Comments
 (0)