Skip to content

Commit ab14d1e

Browse files
author
Jeremiah VALERIE
committed
Merge branch '0.12' into 0.13
2 parents 161fda8 + d0b9710 commit ab14d1e

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

src/Transformer/ArgumentsTransformer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ public function getInstanceAndValidate(string $argType, $data, ResolveInfo $info
148148
{
149149
$isRequired = '!' === $argType[\strlen($argType) - 1];
150150
$isMultiple = '[' === $argType[0];
151-
$endIndex = ($isRequired ? 1 : 0) + ($isMultiple ? 1 : 0);
151+
$isStrictMultiple = false;
152+
if ($isMultiple) {
153+
$isStrictMultiple = '!' === $argType[\strpos($argType, ']') - 1];
154+
}
155+
156+
$endIndex = ($isRequired ? 1 : 0) + ($isMultiple ? 1 : 0) + ($isStrictMultiple ? 1 : 0);
152157
$type = \substr($argType, $isMultiple ? 1 : 0, $endIndex > 0 ? -$endIndex : \strlen($argType));
153158

154159
$result = $this->populateObject($this->getType($type, $info), $data, $isMultiple, $info);

tests/Transformer/ArgumentsTransformerTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace Overblog\GraphQLBundle\Tests\Transformer;
66

7+
use Generator;
78
use GraphQL\Type\Definition\EnumType;
89
use GraphQL\Type\Definition\InputObjectType;
10+
use GraphQL\Type\Definition\ListOfType;
11+
use GraphQL\Type\Definition\NonNull;
912
use GraphQL\Type\Definition\ResolveInfo;
1013
use GraphQL\Type\Definition\Type;
1114
use GraphQL\Type\Schema;
@@ -294,4 +297,75 @@ public function testRaisedErrorsForMultipleInputs(): void
294297
$this->assertEquals($e->toState(), $expected);
295298
}
296299
}
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+
}
297371
}

0 commit comments

Comments
 (0)