tjventurini / graphql-exceptions
客户端保存异常,用于lighthouse-php的GraphQL实现。
v0.0.7
2021-03-03 19:35 UTC
Requires
- illuminate/support: ^6.0|^7.0|^8.0
README
为lighthouse-php的GraphQL实现提供更好的客户端保存异常。
安装
composer require tjventurini/graphql-exceptions
使用
GraphQLExceptions
门面提供了一个方便的 wrap
方法,您可以使用它来放置您的逻辑。如果抛出的错误与配置中提供的异常匹配,它将将其解析为客户端保存的GraphQL异常。
use Tjventurini\GraphQLExceptions\Facades\GraphqlExceptions; GraphQLExceptions::wrap(function() { // your logic });
配置
在 graphql-exceptions
配置中,您可以定义默认要抛出的异常以及一个异常映射,我们使用它来解决抛出的异常与客户端保存的异常。
/* |-------------------------------------------------------------------------- | Exception Map |-------------------------------------------------------------------------- | | In the following array you can add exceptions to be resolved. | */ 'exception_map' => [ Illuminate\Validation\ValidationException::class => Tjventurini\GraphQLExceptions\Exceptions\ClientSaveValidationGraphQLException::class, Illuminate\Database\Eloquent\ModelNotFoundException::class => Tjventurini\GraphQLExceptions\Exceptions\ClientSaveModelNotFoundGraphQLException::class, Illuminate\Auth\AuthenticationException::class => Tjventurini\GraphQLExceptions\Exceptions\ClientSaveAuthenticationGraphQLException::class, ], /* |-------------------------------------------------------------------------- | Default Exception |-------------------------------------------------------------------------- | | The following exception will be thrown when no matching exception was | found in the exception map. | */ 'default_exception' => Tjventurini\GraphQLExceptions\Exceptions\ClientSaveInternalGraphQLException::class,