mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 04:46:04 +03:00
Error formatting: display error extensions under extensions
key
This commit is contained in:
parent
39df711eac
commit
f4008f0fb2
20
CHANGELOG.md
20
CHANGELOG.md
@ -1,4 +1,24 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
## dev-master
|
||||||
|
- Spec compliance: error extensions are displayed under `extensions` key
|
||||||
|
|
||||||
|
#### v0.12.5
|
||||||
|
- Execution performance optimization for lists
|
||||||
|
|
||||||
|
#### v0.12.4
|
||||||
|
- Allow stringeable objects to be serialized by StringType (#303)
|
||||||
|
|
||||||
|
#### v0.12.3
|
||||||
|
- StandardServer: add support for the multipart/form-data content type (#300)
|
||||||
|
|
||||||
|
#### v0.12.2
|
||||||
|
- SchemaPrinter: Use multi-line block for trailing quote (#294)
|
||||||
|
|
||||||
|
#### v0.12.1
|
||||||
|
- Fixed bug in validation rule OverlappingFieldsCanBeMerged (#292)
|
||||||
|
- Added one more breaking change note in UPGRADE.md (#291)
|
||||||
|
- Spec compliance: remove `data` entry from response on top-level error (#281)
|
||||||
|
|
||||||
## v0.12.0
|
## v0.12.0
|
||||||
- RFC: Block String (multi-line strings via triple-quote """string""")
|
- RFC: Block String (multi-line strings via triple-quote """string""")
|
||||||
- GraphQL Schema SDL: Descriptions as strings (including multi-line)
|
- GraphQL Schema SDL: Descriptions as strings (including multi-line)
|
||||||
|
37
UPGRADE.md
37
UPGRADE.md
@ -1,3 +1,40 @@
|
|||||||
|
## Upgrade v0.12.x > dev-master
|
||||||
|
|
||||||
|
### Breaking: minimum supported version of PHP
|
||||||
|
New minimum required version of PHP is **7.1+**
|
||||||
|
|
||||||
|
### Breaking: errors formatting changed according to spec
|
||||||
|
Extensions assigned to errors are shown under `extensions` key
|
||||||
|
```php
|
||||||
|
$e = new Error(
|
||||||
|
'msg',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
['foo' => 'bar']
|
||||||
|
);
|
||||||
|
```
|
||||||
|
Formatting before the change:
|
||||||
|
```
|
||||||
|
'errors' => [
|
||||||
|
[
|
||||||
|
'message' => 'msg',
|
||||||
|
'foo' => 'bar'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
After the change:
|
||||||
|
```
|
||||||
|
'errors' => [
|
||||||
|
[
|
||||||
|
'message' => 'msg',
|
||||||
|
'extensions' => ['foo' => 'bar'],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## Upgrade v0.11.x > v0.12.x
|
## Upgrade v0.11.x > v0.12.x
|
||||||
|
|
||||||
### Breaking: Minimum supported version is PHP5.6
|
### Breaking: Minimum supported version is PHP5.6
|
||||||
|
@ -326,10 +326,6 @@ class Error extends \Exception implements \JsonSerializable, ClientAware
|
|||||||
'message' => $this->getMessage(),
|
'message' => $this->getMessage(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->getExtensions()) {
|
|
||||||
$arr = array_merge($this->getExtensions(), $arr);
|
|
||||||
}
|
|
||||||
|
|
||||||
$locations = Utils::map(
|
$locations = Utils::map(
|
||||||
$this->getLocations(),
|
$this->getLocations(),
|
||||||
function (SourceLocation $loc) {
|
function (SourceLocation $loc) {
|
||||||
@ -343,6 +339,9 @@ class Error extends \Exception implements \JsonSerializable, ClientAware
|
|||||||
if (! empty($this->path)) {
|
if (! empty($this->path)) {
|
||||||
$arr['path'] = $this->path;
|
$arr['path'] = $this->path;
|
||||||
}
|
}
|
||||||
|
if (! empty($this->extensions)) {
|
||||||
|
$arr['extensions'] = $this->extensions;
|
||||||
|
}
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
@ -187,23 +187,21 @@ class FormattedError
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($e instanceof Error) {
|
if ($e instanceof Error) {
|
||||||
if ($e->getExtensions()) {
|
|
||||||
$formattedError = array_merge($e->getExtensions(), $formattedError);
|
|
||||||
}
|
|
||||||
|
|
||||||
$locations = Utils::map(
|
$locations = Utils::map(
|
||||||
$e->getLocations(),
|
$e->getLocations(),
|
||||||
function (SourceLocation $loc) {
|
function (SourceLocation $loc) {
|
||||||
return $loc->toSerializableArray();
|
return $loc->toSerializableArray();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (! empty($locations)) {
|
if (! empty($locations)) {
|
||||||
$formattedError['locations'] = $locations;
|
$formattedError['locations'] = $locations;
|
||||||
}
|
}
|
||||||
if (! empty($e->path)) {
|
if (! empty($e->path)) {
|
||||||
$formattedError['path'] = $e->path;
|
$formattedError['path'] = $e->path;
|
||||||
}
|
}
|
||||||
|
if (! empty($e->getExtensions())) {
|
||||||
|
$formattedError['extensions'] = $e->getExtensions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($debug) {
|
if ($debug) {
|
||||||
|
@ -146,6 +146,9 @@ class ErrorTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(['foo' => 'bar'], $e->getExtensions());
|
$this->assertEquals(['foo' => 'bar'], $e->getExtensions());
|
||||||
$this->assertEquals(['message' => 'msg', 'foo' => 'bar'], $e->toSerializableArray());
|
$this->assertEquals([
|
||||||
|
'message' => 'msg',
|
||||||
|
'extensions' => ['foo' => 'bar'],
|
||||||
|
], $e->toSerializableArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,51 @@ use GraphQL\Error\Error;
|
|||||||
use GraphQL\Error\FormattedError;
|
use GraphQL\Error\FormattedError;
|
||||||
use GraphQL\Language\Parser;
|
use GraphQL\Language\Parser;
|
||||||
use GraphQL\Language\Source;
|
use GraphQL\Language\Source;
|
||||||
|
use GraphQL\Language\SourceLocation;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class PrintErrorTest extends TestCase
|
class PrintErrorTest extends TestCase
|
||||||
{
|
{
|
||||||
// Describe printError
|
// Describe printError
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @it prints an line numbers with correct padding
|
||||||
|
*/
|
||||||
|
public function testPrintsAnLineNumbersWithCorrectPadding()
|
||||||
|
{
|
||||||
|
$singleDigit = new Error(
|
||||||
|
'Single digit line number with no padding',
|
||||||
|
null,
|
||||||
|
new Source('*', 'Test', new SourceLocation(9, 1)),
|
||||||
|
[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
$actual = FormattedError::printError($singleDigit);
|
||||||
|
$expected = 'Single digit line number with no padding
|
||||||
|
|
||||||
|
Test (9:1)
|
||||||
|
9: *
|
||||||
|
^
|
||||||
|
';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
|
||||||
|
$doubleDigit = new Error(
|
||||||
|
'Left padded first line number',
|
||||||
|
null,
|
||||||
|
new Source("*\n", 'Test', new SourceLocation(9, 1)),
|
||||||
|
[0]
|
||||||
|
);
|
||||||
|
$actual = FormattedError::printError($doubleDigit);
|
||||||
|
$expected = 'Left padded first line number
|
||||||
|
|
||||||
|
Test (9:1)
|
||||||
|
9: *
|
||||||
|
^
|
||||||
|
10:
|
||||||
|
';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it prints an error with nodes from different sources
|
* @it prints an error with nodes from different sources
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user