Skip to content

Commit 35f0034

Browse files
committed
Issue-13: Fixed issue that prevented null arguments from getting sets in query string
1 parent 06b91cd commit 35f0034

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected function constructArguments(): string
189189
}
190190

191191
// Convert argument values to graphql string literal equivalent
192-
if (is_scalar($value)) {
192+
if (is_scalar($value) || $value === null) {
193193
// Convert scalar value to its literal in graphql
194194
$value = StringLiteralFormatter::formatValueForRHS($value);
195195
} elseif (is_array($value)) {

tests/QueryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,31 @@ public function testBooleanArgumentValue(Query $query)
353353
return $query;
354354
}
355355

356+
/**
357+
* @depends clone testEmptyArguments
358+
*
359+
* @covers \GraphQL\Query::setArguments
360+
* @covers \GraphQL\Query::constructArguments
361+
*
362+
* @param Query $query
363+
*
364+
* @return Query
365+
*/
366+
public function testNullArgumentValue(Query $query)
367+
{
368+
$query->setArguments(['arg1' => null]);
369+
$this->assertEquals(
370+
"query {
371+
Object(arg1: null) {
372+
373+
}
374+
}"
375+
, (string) $query
376+
);
377+
378+
return $query;
379+
}
380+
356381
/**
357382
* @depends clone testEmptyArguments
358383
*

0 commit comments

Comments
 (0)