Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tjventurini/graphql-exceptions
Client save exceptions for lighthouse-php graphql implementation.
https://github.com/tjventurini/graphql-exceptions
Last synced: 10 days ago
JSON representation
Client save exceptions for lighthouse-php graphql implementation.
- Host: GitHub
- URL: https://github.com/tjventurini/graphql-exceptions
- Owner: tjventurini
- License: mit
- Created: 2020-10-26T03:21:42.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-03T19:35:51.000Z (over 3 years ago)
- Last Synced: 2024-04-21T03:49:02.963Z (7 months ago)
- Language: PHP
- Size: 19.5 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Graphql Exceptions
Better client save exceptions for the lighthouse-php graphql implementation.
## Installation
```
composer require tjventurini/graphql-exceptions
```## Usage
The `GraphQLExceptions` facade provides a convenient `wrap` method that accepts a `Closure` that you can use to put your logic in. If a thrown error matches the exceptions provided in the configuration it will resolve it to a client save graphql exception.
```php
use Tjventurini\GraphQLExceptions\Facades\GraphqlExceptions;GraphQLExceptions::wrap(function() {
// your logic
});
```## Configuration
In the `graphql-exceptions` configuration you can define the default exception to throw and an exception map that we use to resolve the thrown exception with a client save exception.
```php
/*
|--------------------------------------------------------------------------
| 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,
```