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

Fix handling of errors in mutations #297

Merged
merged 4 commits into from
Oct 8, 2018
Merged

Conversation

crisu83
Copy link
Contributor

@crisu83 crisu83 commented Oct 8, 2018

No description provided.

@crisu83 crisu83 added bug Something isn't working execution Related to execution labels Oct 8, 2018
@crisu83 crisu83 added this to the Version 1.0 milestone Oct 8, 2018
@crisu83 crisu83 self-assigned this Oct 8, 2018
@crisu83 crisu83 requested review from hungneox and Jalle19 October 8, 2018 06:49
@@ -114,8 +114,8 @@ public function execute(): ?array
$result = $operation->getOperation() === 'mutation'
? $this->executeFieldsSerially($objectType, $rootValue, $path, $fields)
: $this->executeFields($objectType, $rootValue, $path, $fields);
} catch (\Throwable $ex) {
$this->handleError(new ExecutionException($ex->getMessage(), $fields, null, null, null, null, $ex));
} catch (ExecutionException $ex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now \Throwable and other exceptions won't ever be caught?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be correct, \Throwables are already elsewhere wrapped after ExecutionExceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we can do is add another catch clause, just to be sure though. Good point.

@crisu83 crisu83 force-pushed the fix-mutation-error-handling branch from 2f21b27 to 50003e9 Compare October 8, 2018 08:08
@@ -217,8 +218,8 @@ public function executeFieldsSerially(

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if $ex is not ExecutionException? Do we lose that exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, clicked the wrong button. I'm also wondering if this is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I've fixed this now.

@@ -379,7 +385,7 @@ protected function executeFields(
continue;
}

$doesContainPromise = $doesContainPromise || $this->isPromise($result);
$doesContainPromise = $doesContainPromise || $result instanceof ExtendedPromiseInterface;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crisu83 Not sure why you don't like the isPromise method, but we use it in ~3 places at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it’s better to use instanceof instead of the @var comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crisu83 If you insist, feel free to change, but we actually don't really use it in the code.

@@ -115,7 +114,7 @@ public function execute(): ?array
? $this->executeFieldsSerially($objectType, $rootValue, $path, $fields)
: $this->executeFields($objectType, $rootValue, $path, $fields);
} catch (\Throwable $ex) {
$this->handleError(new ExecutionException($ex->getMessage(), $fields, null, null, null, null, $ex));
$this->handleError(new ExecutionException($ex->getMessage(), null, null, null, null, null, $ex));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crisu83 not sure why you removed the $fields?

@crisu83 crisu83 merged commit 9fbb8cd into master Oct 8, 2018
@crisu83 crisu83 deleted the fix-mutation-error-handling branch October 8, 2018 20:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working execution Related to execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants