diff --git a/CHANGELOG.md b/CHANGELOG.md index 799c8c7..ef877fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Make `Result::assertErrorFree()` return void + ## v0.33.1 ### Fixed diff --git a/README.md b/README.md index dcb92f2..f37cf44 100644 --- a/README.md +++ b/README.md @@ -198,25 +198,35 @@ $result = \Example\Api\Operations\HelloSailor::execute(); ``` The returned `$result` is going to be a class that extends `\Spawnia\Sailor\Result` and -holds the decoded response returned from the server. You can just grab the `$data`, `$errors` -or `$extensions` off of it: +holds the decoded response returned from the server. +You can just grab the `$data`, `$errors` or `$extensions` off of it: ```php -$catchResult->data // `null` or a generated subclass of `\Spawnia\Sailor\ObjectLike` -$catchResult->errors // `null` or a list of `\Spawnia\Sailor\Error\Error` -$catchResult->extensions // `null` or an arbitrary map +$result->data // `null` or a generated subclass of `\Spawnia\Sailor\ObjectLike` +$result->errors // `null` or a list of `\Spawnia\Sailor\Error\Error` +$result->extensions // `null` or an arbitrary map ``` ### Error handling -You can ensure your query returned the proper data and contained no errors: +You can ensure an operation returned the proper data and contained no errors: ```php $errorFreeResult = \Example\Api\Operations\HelloSailor::execute() ->errorFree(); // Throws if there are errors or returns an error free result ``` -If you don't need any data, but want to ensure a mutation succeeded: +The `$errorFreeResult` is going to be a class that extends `\Spawnia\Sailor\ErrorFreeResult`. +Given it can only be obtained by going through validation, +it is guaranteed to have non-null `$data` and does not have `$errors`: + +```php +$errorFreeResult->data // a generated subclass of `\Spawnia\Sailor\ObjectLike` +$errorFreeResult->extensions // `null` or an arbitrary map +``` + +If you do not need to access the data and just want to ensure a mutation was successful, +the following is more efficient as it does not instantiate a new object: ```php \Example\Api\Operations\SomeMutation::execute() diff --git a/src/Result.php b/src/Result.php index 77c2d47..e1c77a3 100644 --- a/src/Result.php +++ b/src/Result.php @@ -94,15 +94,11 @@ static function (\stdClass $raw) use ($endpoint): Error { * Throw an exception if errors are present in the result. * * @throws ResultErrorsException - * - * @return $this */ - public function assertErrorFree(): self + public function assertErrorFree(): void { if (isset($this->errors)) { throw new ResultErrorsException($this->errors, static::config(), static::endpoint()); } - - return $this; } }