Skip to content

Commit 2348937

Browse files
authored
Merge pull request #10 from Fooriva/master
Fix null default value error on queries parameters
2 parents a4bafbd + bd6f6ca commit 2348937

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/QueryField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(string $name, TypeInterface $type, array $arguments,
6161
} elseif ($type->getKind() === TypeMap::KIND_INPUT_OBJECT) {
6262
$val = $this->hydrator->hydrate($val, $type);
6363
}
64-
} elseif (isset($arr['default'])) {
64+
} elseif (array_key_exists('default', $arr)) {
6565
$val = $arr['default'];
6666
} else {
6767
throw new GraphQLException("Expected argument '$name' was not provided.");

tests/ControllerQueryProviderTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,25 @@ public function testQueryProvider()
5252

5353
$mockResolveInfo = $this->createMock(ResolveInfo::class);
5454

55-
$result = $usersQuery->resolve('foo', ['int'=>42, 'string'=>'foo', 'list'=>[
56-
['test'=>42],
57-
['test'=>12],
58-
],
55+
$context = ['int'=>42, 'string'=>'foo', 'list'=>[
56+
['test'=>42],
57+
['test'=>12],
58+
],
5959
'boolean'=>true,
6060
'float'=>4.2,
6161
'dateTimeImmutable'=>'2017-01-01 01:01:01',
6262
'dateTime'=>'2017-01-01 01:01:01'
63-
], $mockResolveInfo);
63+
];
64+
65+
$result = $usersQuery->resolve('foo', $context, $mockResolveInfo);
6466

6567
$this->assertInstanceOf(TestObject::class, $result);
6668
$this->assertSame('foo424212true4.22017010101010120170101010101default', $result->getTest());
69+
70+
unset($context['string']); // Testing null default value
71+
$result = $usersQuery->resolve('foo', $context, $mockResolveInfo);
72+
73+
$this->assertSame('424212true4.22017010101010120170101010101default', $result->getTest());
6774
}
6875

6976
public function testMutations()

tests/Fixtures/TestController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ class TestController
1313
/**
1414
* @Query
1515
* @param int $int
16-
* @param null|string $string
1716
* @param TestObject[] $list
1817
* @param bool|null $boolean
1918
* @param float|null $float
2019
* @param \DateTimeImmutable|null $dateTimeImmutable
21-
* @param \DateTime|null $dateTime
20+
* @param \DateTime|\DateTimeInterface|null $dateTime
21+
* @param string $withDefault
22+
* @param null|string $string
2223
* @return TestObject
2324
*/
24-
public function test(int $int, ?string $string, array $list, ?bool $boolean, ?float $float, ?\DateTimeImmutable $dateTimeImmutable, ?\DateTimeInterface $dateTime, string $withDefault = 'default'): TestObject
25+
public function test(int $int, array $list, ?bool $boolean, ?float $float, ?\DateTimeImmutable $dateTimeImmutable, ?\DateTimeInterface $dateTime, string $withDefault = 'default', ?string $string = null): TestObject
2526
{
2627
$str = '';
2728
foreach ($list as $test) {

0 commit comments

Comments
 (0)