Unverified Commit ce2bc1f7 authored by Alex Tkachev's avatar Alex Tkachev Committed by GitHub
Browse files

fix(Condition): Fix array_pad() call with NULL values (#1340)

parent b9614c5b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ class Condition implements ResolverInterface {
   */
  public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
    $branches = $this->branches;
    while ([$condition, $resolver] = array_pad(array_shift($branches), 2, NULL)) {
    while ($branch = array_shift($branches)) {
      [$condition, $resolver] = array_pad($branch, 2, NULL);
      if ($condition instanceof ResolverInterface) {
        if (($condition = $condition->resolve($value, $args, $context, $info, $field)) === NULL) {
          // Bail out early if a resolver returns NULL.
+20 −0
Original line number Diff line number Diff line
@@ -231,6 +231,26 @@ GQL;
    $this->assertResults($query, [], ['tree' => ['context' => ['myContext' => 'my context value']]]);
  }

  /**
   * @covers ::cond
   */
  public function testSingleCond(): void {
    $this->mockResolver('Query', 'me', $this->builder->cond([
      [
        $this->builder->fromValue(FALSE),
        $this->builder->fromValue('This should resolve into null.'),
      ],
    ]));

    $query = <<<GQL
      query {
        me
      }
GQL;

    $this->assertResults($query, [], ['me' => NULL]);
  }

  /**
   * @covers ::cond
   */