From af5163ee5542f77f3f2dfaadeffe68a0f1ae837d Mon Sep 17 00:00:00 2001 From: Christoffer Niska Date: Wed, 5 Sep 2018 13:00:03 +0300 Subject: [PATCH] Fix error bubbling for executeFieldsSerially --- src/Execution/Executor.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Execution/Executor.php b/src/Execution/Executor.php index 4e29a907..3df58465 100644 --- a/src/Execution/Executor.php +++ b/src/Execution/Executor.php @@ -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; @@ -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]; @@ -208,6 +207,8 @@ public function executeFieldsSerially( $promise->then(function ($resolvedResults) use (&$finalResults) { $finalResults = $resolvedResults ?? []; + })->otherwise(function ($ex) { + $this->context->addError($ex); }); return $finalResults; @@ -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; } @@ -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) {