diff --git a/src/Exceptions/GraphQLException.php b/src/Exceptions/GraphQLException.php index c874291a5c..c6afc58a4c 100644 --- a/src/Exceptions/GraphQLException.php +++ b/src/Exceptions/GraphQLException.php @@ -14,7 +14,6 @@ public function __construct( string $message, int $code = 0, Throwable|null $previous = null, - protected string $category = 'Exception', protected array $extensions = [], ) { parent::__construct($message, $code, $previous); @@ -28,16 +27,6 @@ public function isClientSafe(): bool return true; } - /** - * Returns string describing a category of the error. - * - * Value "graphql" is reserved for errors produced by query parsing or validation, do not use it. - */ - public function getCategory(): string - { - return $this->category; - } - /** * Returns the "extensions" object attached to the GraphQL error. * diff --git a/src/Mappers/PorpaginasMissingParameterException.php b/src/Mappers/PorpaginasMissingParameterException.php index 1af433520f..afb40e377d 100644 --- a/src/Mappers/PorpaginasMissingParameterException.php +++ b/src/Mappers/PorpaginasMissingParameterException.php @@ -28,14 +28,4 @@ public function isClientSafe(): bool { return true; } - - /** - * Returns string describing a category of the error. - * - * Value "graphql" is reserved for errors produced by query parsing or validation, do not use it. - */ - public function getCategory(): string - { - return 'pagination'; - } } diff --git a/src/Middlewares/MissingAuthorizationException.php b/src/Middlewares/MissingAuthorizationException.php index e04edd2d6d..4b9a4758c6 100644 --- a/src/Middlewares/MissingAuthorizationException.php +++ b/src/Middlewares/MissingAuthorizationException.php @@ -26,14 +26,4 @@ public function isClientSafe(): bool { return true; } - - /** - * Returns string describing a category of the error. - * - * Value "graphql" is reserved for errors produced by query parsing or validation, do not use it. - */ - public function getCategory(): string - { - return 'security'; - } } diff --git a/src/Parameters/MissingArgumentException.php b/src/Parameters/MissingArgumentException.php index be48cd5564..d906f8063f 100644 --- a/src/Parameters/MissingArgumentException.php +++ b/src/Parameters/MissingArgumentException.php @@ -81,16 +81,6 @@ public function isClientSafe(): bool return true; } - /** - * Returns string describing a category of the error. - * - * Value "graphql" is reserved for errors produced by query parsing or validation, do not use it. - */ - public function getCategory(): string - { - return 'graphql'; - } - /** * Returns the "extensions" object attached to the GraphQL error. * diff --git a/tests/Exceptions/ErrorHandlerTest.php b/tests/Exceptions/ErrorHandlerTest.php index 637499ec57..9c20b86d38 100644 --- a/tests/Exceptions/ErrorHandlerTest.php +++ b/tests/Exceptions/ErrorHandlerTest.php @@ -10,7 +10,7 @@ class ErrorHandlerTest extends TestCase public function testErrorFormatter() { - $exception = new GraphQLException('foo', 0, null, 'MyCategory', ['field' => 'foo']); + $exception = new GraphQLException('foo', 0, null, ['field' => 'foo']); $error = new Error('foo', null, null, [], null, $exception); $formattedError = WebonyxErrorHandler::errorFormatter($error); $this->assertSame([ @@ -23,7 +23,7 @@ public function testErrorFormatter() public function testErrorHandler() { - $exception = new GraphQLException('foo', 0, null, 'MyCategory', ['field' => 'foo']); + $exception = new GraphQLException('foo', 0, null, ['field' => 'foo']); $error = new Error('bar', null, null, [], null, $exception); $aggregateException = new GraphQLAggregateException(); $aggregateException->add($exception); diff --git a/tests/Http/HttpCodeDeciderTest.php b/tests/Http/HttpCodeDeciderTest.php index dd82364c74..d7a0629da5 100644 --- a/tests/Http/HttpCodeDeciderTest.php +++ b/tests/Http/HttpCodeDeciderTest.php @@ -38,11 +38,6 @@ public function isClientSafe():bool { return true; } - - public function getCategory() - { - return 'foo'; - } }; $clientAwareError = new Error('Foo', null, null, [], null, $clientAwareException); diff --git a/tests/Parameters/MissingArgumentExceptionTest.php b/tests/Parameters/MissingArgumentExceptionTest.php index 9c0ba460f0..c4b7eec3dc 100644 --- a/tests/Parameters/MissingArgumentExceptionTest.php +++ b/tests/Parameters/MissingArgumentExceptionTest.php @@ -21,6 +21,5 @@ public function testWrapWithFactoryContext(): void $this->assertTrue($e->isClientSafe()); $this->assertSame([], $e->getExtensions()); - $this->assertSame('graphql', $e->getCategory()); } } diff --git a/website/docs/error-handling.mdx b/website/docs/error-handling.mdx index 549a9c15c9..1fe32a54de 100644 --- a/website/docs/error-handling.mdx +++ b/website/docs/error-handling.mdx @@ -12,10 +12,7 @@ In GraphQL, when an error occurs, the server must add an "error" entry in the re { "message": "Name for character with ID 1002 could not be fetched.", "locations": [ { "line": 6, "column": 7 } ], - "path": [ "hero", "heroFriends", 1, "name" ], - "extensions": { - "category": "Exception" - } + "path": [ "hero", "heroFriends", 1, "name" ] } ] } @@ -43,30 +40,6 @@ throw new GraphQLException("Not found", 404);
GraphQL allows to have several errors for one request. If you have several GraphQLException thrown for the same request, the HTTP status code used will be the highest one.
-## Customizing the category - -By default, GraphQLite adds a "category" entry in the "extensions section". You can customize the category with the -4th parameter of the constructor: - -```php -throw new GraphQLException("Not found", 404, null, "NOT_FOUND"); -``` - -will generate: - -```json -{ - "errors": [ - { - "message": "Not found", - "extensions": { - "category": "NOT_FOUND" - } - } - ] -} -``` - ## Customizing the extensions section You can customize the whole "extensions" section with the 5th parameter of the constructor: @@ -83,7 +56,6 @@ will generate: { "message": "Field required", "extensions": { - "category": "VALIDATION", "field": "name" } } @@ -109,16 +81,6 @@ class ValidationException extends Exception implements GraphQLExceptionInterface return true; } - /** - * Returns string describing a category of the error. - * - * Value "graphql" is reserved for errors produced by query parsing or validation, do not use it. - */ - public function getCategory(): string - { - return 'VALIDATION'; - } - /** * Returns the "extensions" object attached to the GraphQL error. * diff --git a/website/docs/laravel-package-advanced.mdx b/website/docs/laravel-package-advanced.mdx index f4f9918427..3341538023 100644 --- a/website/docs/laravel-package-advanced.mdx +++ b/website/docs/laravel-package-advanced.mdx @@ -43,15 +43,13 @@ If a validation fails to pass, the message will be printed in the "errors" secti { "message": "The email must be a valid email address.", "extensions": { - "argument": "email", - "category": "Validate" + "argument": "email" } }, { "message": "The password must be greater than or equal 8 characters.", "extensions": { - "argument": "password", - "category": "Validate" + "argument": "password" } } ] diff --git a/website/docs/validation.mdx b/website/docs/validation.mdx index 3b8ac86ac2..13a05188fd 100644 --- a/website/docs/validation.mdx +++ b/website/docs/validation.mdx @@ -96,8 +96,7 @@ If a validation fails, GraphQLite will return the failed validations in the "err "message": "The email '\"foo@thisdomaindoesnotexistatall.com\"' is not a valid email.", "extensions": { "code": "bf447c1c-0266-4e10-9c6c-573df282e413", - "field": "email", - "category": "Validate" + "field": "email" } } ]