From ced09ea9dfefe87b3b5b159fab0f9c5144b61c7d Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sat, 27 Jul 2024 11:29:51 +0200 Subject: [PATCH] feat: deprecate Error utils --- README.md | 78 ------------------------------------ src/Error/Error.php | 1 + src/Error/FormattedError.php | 1 + 3 files changed, 2 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index e24f36c..f9f1ea7 100644 --- a/README.md +++ b/README.md @@ -263,84 +263,6 @@ $character = new UnionType( ); ``` -### Error Handling - -Extending your exception with `SimPod\GraphQLUtils\Error\Error` forces you to implement `getType()` method. - -Example Error class - -```php -isClientSafe()) { - // eg. log error - } - - return FormattedError::createFromException($error); -}; - -$errorFormatterCallback = static function (Error $error) use ($formatError) : array { - return $formatError($error); -}; - -$config = GraphQL::executeQuery(/* $args */) - ->setErrorFormatter($errorFormatterCallback) - ->setErrorsHandler( - static function (array $errors, callable $formatter) : array { - return array_map($formatter, $errors); - } - ); -``` - -Error types will then be provided in your response so client can easier identify the error type - -```json -{ - "errors": [ - { - "message": "No CustomerId provided", - "extensions": { - "type": "INVALID_CUSTOMER_ID_PROVIDED", - "category": "validation" - } - } - ] -} -``` - [GA Image]: https://github.com/simPod/GraphQL-Utils/workflows/CI/badge.svg [GA Link]: https://github.com/simPod/GraphQL-Utils/actions?query=workflow%3A%22CI%22+branch%3A0.7.x diff --git a/src/Error/Error.php b/src/Error/Error.php index aed644c..be642d1 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -4,6 +4,7 @@ namespace SimPod\GraphQLUtils\Error; +/** @deprecated Use {@see ProvidesExtensions} */ abstract class Error extends \GraphQL\Error\Error { abstract public function getType(): string; diff --git a/src/Error/FormattedError.php b/src/Error/FormattedError.php index 8495a90..3fae5dd 100644 --- a/src/Error/FormattedError.php +++ b/src/Error/FormattedError.php @@ -7,6 +7,7 @@ use GraphQL\Error\DebugFlag; use Throwable; +/** @deprecated Use {@see ProvidesExtensions} */ class FormattedError extends \GraphQL\Error\FormattedError { public static function createFromException(Throwable $exception, int $debugFlag = DebugFlag::NONE, string|null $internalErrorMessage = null): array