Skip to content

Commit

Permalink
Add support for ^0.13 webonyx/graphql-php
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Nov 27, 2018
1 parent fcd8e17 commit 8a50d70
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ Error types will then be provided in your response so client can easier identify
{
"errors": [
{
"type": "INVALID_CUSTOMER_ID_PROVIDED",
"message": "No CustomerId provided",
"category": "graphql",
...
"extensions": {
"type": "INVALID_CUSTOMER_ID_PROVIDED",
"category": "graphql"
}
}
]
}
```
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"require": {
"php": "^7.2",
"webonyx/graphql-php": "^0.12"
"webonyx/graphql-php": "^0.12 || ^0.13"
},
"require-dev": {
"doctrine/coding-standard": "^5.0",
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ parameters:
paths:
- %currentWorkingDirectory%/src
- %currentWorkingDirectory%/tests
tmpDir: %currentWorkingDirectory%/var/phpstan
ignoreErrors:
- "~Method SimPod\\\\GraphQLUtils\\\\Error\\\\FormattedError::createFromException\\(\\) has parameter \\$\\w+ with no typehint specified~"
# https://github.com/webonyx/graphql-php/pull/406
- "~Parameter \\#1 \\$vars of class GraphQL\\\\Language\\\\AST\\\\BooleanValueNode constructor expects array<GraphQL\\\\Language\\\\AST\\\\Location\\|GraphQL\\\\Language\\\\AST\\\\NameNode\\|GraphQL\\\\Language\\\\AST\\\\NodeList\\|GraphQL\\\\Language\\\\AST\\\\SelectionSetNode\\|string\\|null>, array<string, false> given~"

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
Expand Down
2 changes: 1 addition & 1 deletion src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace SimPod\GraphQLUtils\Error;

/**
* @inheritdoc
* {@inheritdoc}
*/
abstract class Error extends \GraphQL\Error\Error
{
Expand Down
7 changes: 3 additions & 4 deletions src/Error/FormattedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
namespace SimPod\GraphQLUtils\Error;

/**
* @inheritdoc
* {@inheritdoc}
*/
class FormattedError extends \GraphQL\Error\FormattedError
{
/**
* @inheritdoc
* {@inheritdoc}
*/
public static function createFromException($e, $debug = false, $internalErrorMessage = null) : array
{
$arrayError = parent::createFromException($e, $debug, $internalErrorMessage);

if ($e instanceof \GraphQL\Error\Error && $e->getPrevious() instanceof Error) {
$type = ['type' => $e->getPrevious()->getType()];
$arrayError = $type + $arrayError;
$arrayError['extensions']['type'] = $e->getPrevious()->getType();
}

return $arrayError;
Expand Down
24 changes: 16 additions & 8 deletions tests/Error/FormattedErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public function testNonDebug() : void

self::assertSame(
[
'message' => 'Internal server error',
'category' => 'internal',
'message' => 'Internal server error',
'extensions' => [
'category' => 'internal',
],
],
FormattedError::createFromException($exception)
);
Expand All @@ -32,7 +34,9 @@ public function testDebug() : void
[
'debugMessage' => 'When smashing sun-dried shrimps, be sure they are room temperature.',
'message' => 'Internal server error',
'category' => 'internal',
'extensions' => [
'category' => 'internal',
],
],
FormattedError::createFromException($exception, true)
);
Expand All @@ -44,8 +48,10 @@ public function testInternalMessageModification() : void

self::assertSame(
[
'message' => 'Try grilling smoothie jumbled with salad cream, decorateed with green curry.',
'category' => 'internal',
'message' => 'Try grilling smoothie jumbled with salad cream, decorateed with green curry.',
'extensions' => [
'category' => 'internal',
],
],
FormattedError::createFromException(
$exception,
Expand All @@ -72,9 +78,11 @@ public function __construct()

self::assertSame(
[
'type' => 'CUSTOM_ERROR',
'message' => 'Error Message',
'category' => 'graphql',
'message' => 'Error Message',
'extensions' => [
'category' => 'graphql',
'type' => 'CUSTOM_ERROR',
],
],
FormattedError::createFromException($error, false)
);
Expand Down

0 comments on commit 8a50d70

Please sign in to comment.