Skip to content

Commit 8a50d70

Browse files
committed
Add support for ^0.13 webonyx/graphql-php
1 parent fcd8e17 commit 8a50d70

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ Error types will then be provided in your response so client can easier identify
182182
{
183183
"errors": [
184184
{
185-
"type": "INVALID_CUSTOMER_ID_PROVIDED",
186185
"message": "No CustomerId provided",
187-
"category": "graphql",
188-
...
186+
"extensions": {
187+
"type": "INVALID_CUSTOMER_ID_PROVIDED",
188+
"category": "graphql"
189+
}
190+
}
191+
]
192+
}
189193
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"require": {
1616
"php": "^7.2",
17-
"webonyx/graphql-php": "^0.12"
17+
"webonyx/graphql-php": "^0.12 || ^0.13"
1818
},
1919
"require-dev": {
2020
"doctrine/coding-standard": "^5.0",

phpstan.neon.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ parameters:
33
paths:
44
- %currentWorkingDirectory%/src
55
- %currentWorkingDirectory%/tests
6-
tmpDir: %currentWorkingDirectory%/var/phpstan
76
ignoreErrors:
8-
- "~Method SimPod\\\\GraphQLUtils\\\\Error\\\\FormattedError::createFromException\\(\\) has parameter \\$\\w+ with no typehint specified~"
7+
# https://github.com/webonyx/graphql-php/pull/406
8+
- "~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~"
99

1010
includes:
1111
- vendor/phpstan/phpstan-phpunit/extension.neon

src/Error/Error.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace SimPod\GraphQLUtils\Error;
66

77
/**
8-
* @inheritdoc
8+
* {@inheritdoc}
99
*/
1010
abstract class Error extends \GraphQL\Error\Error
1111
{

src/Error/FormattedError.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
namespace SimPod\GraphQLUtils\Error;
66

77
/**
8-
* @inheritdoc
8+
* {@inheritdoc}
99
*/
1010
class FormattedError extends \GraphQL\Error\FormattedError
1111
{
1212
/**
13-
* @inheritdoc
13+
* {@inheritdoc}
1414
*/
1515
public static function createFromException($e, $debug = false, $internalErrorMessage = null) : array
1616
{
1717
$arrayError = parent::createFromException($e, $debug, $internalErrorMessage);
1818

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

2423
return $arrayError;

tests/Error/FormattedErrorTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public function testNonDebug() : void
1717

1818
self::assertSame(
1919
[
20-
'message' => 'Internal server error',
21-
'category' => 'internal',
20+
'message' => 'Internal server error',
21+
'extensions' => [
22+
'category' => 'internal',
23+
],
2224
],
2325
FormattedError::createFromException($exception)
2426
);
@@ -32,7 +34,9 @@ public function testDebug() : void
3234
[
3335
'debugMessage' => 'When smashing sun-dried shrimps, be sure they are room temperature.',
3436
'message' => 'Internal server error',
35-
'category' => 'internal',
37+
'extensions' => [
38+
'category' => 'internal',
39+
],
3640
],
3741
FormattedError::createFromException($exception, true)
3842
);
@@ -44,8 +48,10 @@ public function testInternalMessageModification() : void
4448

4549
self::assertSame(
4650
[
47-
'message' => 'Try grilling smoothie jumbled with salad cream, decorateed with green curry.',
48-
'category' => 'internal',
51+
'message' => 'Try grilling smoothie jumbled with salad cream, decorateed with green curry.',
52+
'extensions' => [
53+
'category' => 'internal',
54+
],
4955
],
5056
FormattedError::createFromException(
5157
$exception,
@@ -72,9 +78,11 @@ public function __construct()
7278

7379
self::assertSame(
7480
[
75-
'type' => 'CUSTOM_ERROR',
76-
'message' => 'Error Message',
77-
'category' => 'graphql',
81+
'message' => 'Error Message',
82+
'extensions' => [
83+
'category' => 'graphql',
84+
'type' => 'CUSTOM_ERROR',
85+
],
7886
],
7987
FormattedError::createFromException($error, false)
8088
);

0 commit comments

Comments
 (0)