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();
|
$isUnsafe = ! $e instanceof ClientAware || ! $e->isClientSafe();
|
||||||
|
|
||||||
if(($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe){
|
if (($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe) {
|
||||||
if ($e->getPrevious()) {
|
if ($e->getPrevious()) {
|
||||||
throw $e->getPrevious();
|
throw $e->getPrevious();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ use GraphQL\Validator\Rules\CustomValidationRule;
|
|||||||
use GraphQL\Validator\ValidationContext;
|
use GraphQL\Validator\ValidationContext;
|
||||||
use function count;
|
use function count;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
use Unsafe;
|
||||||
|
|
||||||
class QueryExecutionTest extends ServerTestCase
|
class QueryExecutionTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
@ -94,11 +95,10 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
'errors' => [
|
'errors' => [
|
||||||
[
|
[
|
||||||
'message' => 'This is the exception we want',
|
'message' => 'This is the exception we want',
|
||||||
|
|
||||||
'path' => ['fieldWithSafeException'],
|
'path' => ['fieldWithSafeException'],
|
||||||
'trace' => []
|
'trace' => [],
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = $this->executeQuery($query)->toArray();
|
$result = $this->executeQuery($query)->toArray();
|
||||||
@ -108,7 +108,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
public function testRethrowUnsafeExceptions() : void
|
public function testRethrowUnsafeExceptions() : void
|
||||||
{
|
{
|
||||||
$this->config->setDebug(Debug::RETHROW_UNSAFE_EXCEPTIONS);
|
$this->config->setDebug(Debug::RETHROW_UNSAFE_EXCEPTIONS);
|
||||||
$this->expectException(UnsafeException::class);
|
$this->expectException(Unsafe::class);
|
||||||
|
|
||||||
$this->executeQuery('
|
$this->executeQuery('
|
||||||
{
|
{
|
||||||
@ -487,7 +487,7 @@ class QueryExecutionTest extends ServerTestCase
|
|||||||
[
|
[
|
||||||
'data' => [
|
'data' => [
|
||||||
'f1' => 'f1',
|
'f1' => 'f1',
|
||||||
'fieldWithSafeException' => null
|
'fieldWithSafeException' => null,
|
||||||
],
|
],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
['message' => 'This is the exception we want'],
|
['message' => 'This is the exception we want'],
|
||||||
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||||||
namespace GraphQL\Tests\Server;
|
namespace GraphQL\Tests\Server;
|
||||||
|
|
||||||
use GraphQL\Deferred;
|
use GraphQL\Deferred;
|
||||||
use GraphQL\Error\ClientAware;
|
|
||||||
use GraphQL\Error\UserError;
|
use GraphQL\Error\UserError;
|
||||||
use GraphQL\Type\Definition\ObjectType;
|
use GraphQL\Type\Definition\ObjectType;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
@ -15,6 +14,7 @@ use function trigger_error;
|
|||||||
use const E_USER_DEPRECATED;
|
use const E_USER_DEPRECATED;
|
||||||
use const E_USER_NOTICE;
|
use const E_USER_NOTICE;
|
||||||
use const E_USER_WARNING;
|
use const E_USER_WARNING;
|
||||||
|
use Unsafe;
|
||||||
|
|
||||||
abstract class ServerTestCase extends TestCase
|
abstract class ServerTestCase extends TestCase
|
||||||
{
|
{
|
||||||
@ -46,13 +46,13 @@ abstract class ServerTestCase extends TestCase
|
|||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function() {
|
'resolve' => function() {
|
||||||
throw new UserError('This is the exception we want');
|
throw new UserError('This is the exception we want');
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
'fieldWithUnsafeException' => [
|
'fieldWithUnsafeException' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => function() {
|
'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' => [
|
'testContextAndRootValue' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
@ -108,30 +108,3 @@ abstract class ServerTestCase extends TestCase
|
|||||||
return $schema;
|
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