Skip to content

Commit

Permalink
Merge a66a285 into 5289a54
Browse files Browse the repository at this point in the history
  • Loading branch information
TamasSzigeti committed Jan 14, 2021
2 parents 5289a54 + a66a285 commit 6eff041
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Executor/ExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ public function toArray(int $debug = DebugFlag::NONE) : array
return array_map($formatter, $errors);
};

$result['errors'] = $errorsHandler(
$handledErrors = $errorsHandler(
$this->errors,
FormattedError::prepareFormatter($this->errorFormatter, $debug)
);

// While we know that there were errors initially, they might have been discarded
if ($handledErrors) {
$result['errors'] = $handledErrors;
}
}

if ($this->data !== null) {
Expand Down
19 changes: 16 additions & 3 deletions tests/Executor/ExecutionResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace GraphQL\Tests\Executor;

use GraphQL\Error\Error;
use GraphQL\Executor\ExecutionResult;
use PHPUnit\Framework\TestCase;

Expand All @@ -13,17 +14,29 @@ public function testToArrayWithoutExtensions() : void
{
$executionResult = new ExecutionResult();

self::assertEquals([], $executionResult->toArray());
self::assertSame([], $executionResult->toArray());
}

public function testToArrayExtensions() : void
{
$executionResult = new ExecutionResult(null, [], ['foo' => 'bar']);

self::assertEquals(['extensions' => ['foo' => 'bar']], $executionResult->toArray());
self::assertSame(['extensions' => ['foo' => 'bar']], $executionResult->toArray());

$executionResult->extensions = ['bar' => 'foo'];

self::assertEquals(['extensions' => ['bar' => 'foo']], $executionResult->toArray());
self::assertSame(['extensions' => ['bar' => 'foo']], $executionResult->toArray());
}

public function testNoEmptyErrors() : void
{
$executionResult = new ExecutionResult(null, [new Error()]);
$executionResult->setErrorsHandler(
static function () : array {
return [];
}
);

self::assertSame([], $executionResult->toArray());
}
}

0 comments on commit 6eff041

Please sign in to comment.