Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Fix error bubbling for executeFieldsSerially #277

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Execution/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Digia\GraphQL\Type\Definition\NamedTypeInterface;
use Digia\GraphQL\Type\Definition\NonNullType;
use Digia\GraphQL\Type\Definition\ObjectType;
use Digia\GraphQL\Type\Definition\ScalarType;
use Digia\GraphQL\Type\Definition\SerializableTypeInterface;
use Digia\GraphQL\Type\Definition\TypeInterface;
use Digia\GraphQL\Type\Definition\UnionType;
Expand Down Expand Up @@ -104,7 +103,7 @@ public function execute(): ?array
$result = $operation->getOperation() === 'mutation'
? $this->executeFieldsSerially($objectType, $rootValue, $path, $fields)
: $this->executeFields($objectType, $rootValue, $path, $fields);
} catch (\Exception $ex) {
} catch (\Throwable $ex) {
$this->context->addError(new ExecutionException($ex->getMessage()));

return [null];
Expand Down Expand Up @@ -208,6 +207,8 @@ public function executeFieldsSerially(

$promise->then(function ($resolvedResults) use (&$finalResults) {
$finalResults = $resolvedResults ?? [];
})->otherwise(function ($ex) {
$this->context->addError($ex);
});

return $finalResults;
Expand Down Expand Up @@ -301,7 +302,7 @@ public function completeValueCatchingError(
}

return $completed;
} catch (\Exception $ex) {
} catch (\Throwable $ex) {
$this->context->addError($this->buildLocatedError($ex, $fieldNodes, $path));
return null;
}
Expand Down Expand Up @@ -376,6 +377,7 @@ protected function executeFields(
if ($doesContainPromise) {
$keys = \array_keys($finalResults);
$promise = promiseAll(\array_values($finalResults));

$promise->then(function ($values) use ($keys, &$finalResults) {
/** @noinspection ForeachSourceInspection */
foreach ($values as $i => $value) {
Expand Down