Skip to content

Commit ce2bc1f

Browse files
authored
fix(Condition): Fix array_pad() call with NULL values (#1340)
1 parent b9614c5 commit ce2bc1f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/GraphQL/Resolver/Condition.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function __construct(array $branches) {
3737
*/
3838
public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
3939
$branches = $this->branches;
40-
while ([$condition, $resolver] = array_pad(array_shift($branches), 2, NULL)) {
40+
while ($branch = array_shift($branches)) {
41+
[$condition, $resolver] = array_pad($branch, 2, NULL);
4142
if ($condition instanceof ResolverInterface) {
4243
if (($condition = $condition->resolve($value, $args, $context, $info, $field)) === NULL) {
4344
// Bail out early if a resolver returns NULL.

tests/src/Kernel/ResolverBuilderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,26 @@ public function testFromContext(): void {
231231
$this->assertResults($query, [], ['tree' => ['context' => ['myContext' => 'my context value']]]);
232232
}
233233

234+
/**
235+
* @covers ::cond
236+
*/
237+
public function testSingleCond(): void {
238+
$this->mockResolver('Query', 'me', $this->builder->cond([
239+
[
240+
$this->builder->fromValue(FALSE),
241+
$this->builder->fromValue('This should resolve into null.'),
242+
],
243+
]));
244+
245+
$query = <<<GQL
246+
query {
247+
me
248+
}
249+
GQL;
250+
251+
$this->assertResults($query, [], ['me' => NULL]);
252+
}
253+
234254
/**
235255
* @covers ::cond
236256
*/

0 commit comments

Comments
 (0)