mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
Fix coding style
This commit is contained in:
parent
e7513e356a
commit
c4fe304efe
@ -247,7 +247,7 @@ class FormattedError
|
||||
|
||||
$isUnsafe = ! $e instanceof ClientAware || ! $e->isClientSafe();
|
||||
|
||||
if(($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe){
|
||||
if (($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe) {
|
||||
if ($e->getPrevious()) {
|
||||
throw $e->getPrevious();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ use GraphQL\Validator\Rules\CustomValidationRule;
|
||||
use GraphQL\Validator\ValidationContext;
|
||||
use function count;
|
||||
use function sprintf;
|
||||
use Unsafe;
|
||||
|
||||
class QueryExecutionTest extends ServerTestCase
|
||||
{
|
||||
@ -94,21 +95,20 @@ class QueryExecutionTest extends ServerTestCase
|
||||
'errors' => [
|
||||
[
|
||||
'message' => 'This is the exception we want',
|
||||
|
||||
'path' => ['fieldWithSafeException'],
|
||||
'trace' => []
|
||||
]
|
||||
]
|
||||
'trace' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$result = $this->executeQuery($query)->toArray();
|
||||
$this->assertArraySubset($expected, $result);
|
||||
}
|
||||
|
||||
|
||||
public function testRethrowUnsafeExceptions() : void
|
||||
{
|
||||
$this->config->setDebug(Debug::RETHROW_UNSAFE_EXCEPTIONS);
|
||||
$this->expectException(UnsafeException::class);
|
||||
$this->expectException(Unsafe::class);
|
||||
|
||||
$this->executeQuery('
|
||||
{
|
||||
@ -487,7 +487,7 @@ class QueryExecutionTest extends ServerTestCase
|
||||
[
|
||||
'data' => [
|
||||
'f1' => 'f1',
|
||||
'fieldWithSafeException' => null
|
||||
'fieldWithSafeException' => null,
|
||||
],
|
||||
'errors' => [
|
||||
['message' => 'This is the exception we want'],
|
||||
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace GraphQL\Tests\Server;
|
||||
|
||||
use GraphQL\Deferred;
|
||||
use GraphQL\Error\ClientAware;
|
||||
use GraphQL\Error\UserError;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
@ -15,6 +14,7 @@ use function trigger_error;
|
||||
use const E_USER_DEPRECATED;
|
||||
use const E_USER_NOTICE;
|
||||
use const E_USER_WARNING;
|
||||
use Unsafe;
|
||||
|
||||
abstract class ServerTestCase extends TestCase
|
||||
{
|
||||
@ -46,13 +46,13 @@ abstract class ServerTestCase extends TestCase
|
||||
'type' => Type::string(),
|
||||
'resolve' => function() {
|
||||
throw new UserError('This is the exception we want');
|
||||
}
|
||||
},
|
||||
],
|
||||
'fieldWithUnsafeException' => [
|
||||
'type' => Type::string(),
|
||||
'resolve' => function() {
|
||||
throw new UnsafeException('This exception should not be shown to the user');
|
||||
}
|
||||
throw new Unsafe('This exception should not be shown to the user');
|
||||
},
|
||||
],
|
||||
'testContextAndRootValue' => [
|
||||
'type' => Type::string(),
|
||||
@ -108,30 +108,3 @@ abstract class ServerTestCase extends TestCase
|
||||
return $schema;
|
||||
}
|
||||
}
|
||||
|
||||
class UnsafeException extends \Exception implements ClientAware
|
||||
{
|
||||
/**
|
||||
* Returns true when exception message is safe to be displayed to a client.
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function isClientSafe()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string describing a category of the error.
|
||||
*
|
||||
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return 'unsafe';
|
||||
}
|
||||
}
|
||||
|
30
tests/Server/Unsafe.php
Normal file
30
tests/Server/Unsafe.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use GraphQL\Error\ClientAware;
|
||||
|
||||
class Unsafe extends \Exception implements ClientAware
|
||||
{
|
||||
/**
|
||||
* Returns true when exception message is safe to be displayed to a client.
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function isClientSafe()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string describing a category of the error.
|
||||
*
|
||||
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return 'unsafe';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user