new Deps
This commit is contained in:
+13
-9
@@ -4,10 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Executor;
|
||||
|
||||
use GraphQL\Error\DebugFlag;
|
||||
use GraphQL\Error\Error;
|
||||
use GraphQL\Error\FormattedError;
|
||||
use JsonSerializable;
|
||||
use function array_map;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Returned after [query execution](executing-queries.md).
|
||||
@@ -125,35 +127,37 @@ class ExecutionResult implements JsonSerializable
|
||||
* If debug argument is passed, output of error formatter is enriched which debugging information
|
||||
* ("debugMessage", "trace" keys depending on flags).
|
||||
*
|
||||
* $debug argument must be either bool (only adds "debugMessage" to result) or sum of flags from
|
||||
* GraphQL\Error\Debug
|
||||
*
|
||||
* @param bool|int $debug
|
||||
* $debug argument must sum of flags from @see \GraphQL\Error\DebugFlag
|
||||
*
|
||||
* @return mixed[]
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function toArray($debug = false)
|
||||
public function toArray(int $debug = DebugFlag::NONE) : array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
if (! empty($this->errors)) {
|
||||
$errorsHandler = $this->errorsHandler ?: static function (array $errors, callable $formatter) {
|
||||
if (count($this->errors ?? []) > 0) {
|
||||
$errorsHandler = $this->errorsHandler ?? static function (array $errors, callable $formatter) : 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) {
|
||||
$result['data'] = $this->data;
|
||||
}
|
||||
|
||||
if (! empty($this->extensions)) {
|
||||
if (count($this->extensions ?? []) > 0) {
|
||||
$result['extensions'] = $this->extensions;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user