mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-29 00:25:17 +03:00
Replaced trigger_error with Warning for resolveType warning
This commit is contained in:
parent
9551569ffe
commit
ed28deda81
@ -6,6 +6,7 @@ final class Warning
|
||||
const NAME_WARNING = 1;
|
||||
const ASSIGN_WARNING = 2;
|
||||
const CONFIG_WARNING = 4;
|
||||
const RESOLVE_TYPE_WARNING = 8;
|
||||
|
||||
const ALL = 7;
|
||||
|
||||
@ -25,6 +26,18 @@ final class Warning
|
||||
}
|
||||
}
|
||||
|
||||
public static function enable($enable = true)
|
||||
{
|
||||
if (true === $enable) {
|
||||
self::$enableWarnings = self::ALL;
|
||||
} else if (false === $enable) {
|
||||
self::$enableWarnings = 0;
|
||||
} else {
|
||||
$enable = (int) $enable;
|
||||
self::$enableWarnings |= $enable;
|
||||
}
|
||||
}
|
||||
|
||||
static function warnOnce($errorMessage, $warningId)
|
||||
{
|
||||
if ((self::$enableWarnings & $warningId) > 0 && !isset(self::$warned[$warningId])) {
|
||||
|
@ -3,9 +3,9 @@ namespace GraphQL\Executor;
|
||||
|
||||
use GraphQL\Error\Error;
|
||||
use GraphQL\Error\InvariantViolation;
|
||||
use GraphQL\Error\Warning;
|
||||
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
|
||||
use GraphQL\Executor\Promise\Promise;
|
||||
use GraphQL\GraphQL;
|
||||
use GraphQL\Language\AST\DocumentNode;
|
||||
use GraphQL\Language\AST\FieldNode;
|
||||
use GraphQL\Language\AST\FragmentDefinitionNode;
|
||||
@ -1023,14 +1023,13 @@ class Executor
|
||||
$runtimeType = $returnType->resolveType($result, $exeContext->contextValue, $info);
|
||||
|
||||
if (null === $runtimeType) {
|
||||
if ($returnType instanceof InterfaceType && !$exeContext->schema->getConfig()->descriptor &&
|
||||
!GraphQL::isIgnoredError(GraphQL::WARNING_ON_IMPLEMENTATION_RESOLUTION)) {
|
||||
trigger_error(
|
||||
if ($returnType instanceof InterfaceType && !$exeContext->schema->getConfig()->descriptor) {
|
||||
Warning::warnOnce(
|
||||
"GraphQL Interface Type `{$returnType->name}` returned `null` from it`s `resolveType` function ".
|
||||
'for value: ' . Utils::printSafe($result) . '. Switching to slow resolution method using `isTypeOf` ' .
|
||||
'of all possible implementations. It degrades query performance significantly. '.
|
||||
' Make sure your `resolveType` always returns valid implementation or throws.',
|
||||
E_USER_WARNING
|
||||
Warning::RESOLVE_TYPE_WARNING
|
||||
);
|
||||
}
|
||||
$runtimeType = self::defaultTypeResolver($result, $exeContext->contextValue, $info, $returnType);
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace GraphQL\Tests\Executor;
|
||||
|
||||
use GraphQL\Deferred;
|
||||
use GraphQL\Error\Warning;
|
||||
use GraphQL\GraphQL;
|
||||
use GraphQL\Schema;
|
||||
use GraphQL\Type\Definition\InterfaceType;
|
||||
@ -85,7 +86,9 @@ class AbstractPromiseTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}';
|
||||
|
||||
Warning::suppress(Warning::RESOLVE_TYPE_WARNING);
|
||||
$result = GraphQL::execute($schema, $query);
|
||||
Warning::enable(Warning::RESOLVE_TYPE_WARNING);
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
@ -170,7 +173,9 @@ class AbstractPromiseTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}';
|
||||
|
||||
Warning::suppress(Warning::RESOLVE_TYPE_WARNING);
|
||||
$result = GraphQL::execute($schema, $query);
|
||||
Warning::enable(Warning::RESOLVE_TYPE_WARNING);
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
|
@ -3,6 +3,7 @@ namespace GraphQL\Tests\Executor;
|
||||
|
||||
require_once __DIR__ . '/TestClasses.php';
|
||||
|
||||
use GraphQL\Error\Warning;
|
||||
use GraphQL\Executor\ExecutionResult;
|
||||
use GraphQL\Executor\Executor;
|
||||
use GraphQL\Error\FormattedError;
|
||||
@ -89,15 +90,14 @@ class AbstractTest extends \PHPUnit_Framework_TestCase
|
||||
]
|
||||
]);
|
||||
|
||||
GraphQL::setIgnoreError(GraphQL::WARNING_ON_IMPLEMENTATION_RESOLUTION);
|
||||
Warning::suppress(Warning::RESOLVE_TYPE_WARNING);
|
||||
$result = Executor::execute($schema, Parser::parse($query));
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
GraphQL::setIgnoreError(GraphQL::WARNING_ON_IMPLEMENTATION_RESOLUTION, false);
|
||||
Warning::enable(Warning::RESOLVE_TYPE_WARNING);
|
||||
$result = Executor::execute($schema, Parser::parse($query));
|
||||
$this->assertEquals(2, count($result->errors));
|
||||
$this->assertEquals(1, count($result->errors));
|
||||
$this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $result->errors[0]->getPrevious());
|
||||
$this->assertInstanceOf('PHPUnit_Framework_Error_Warning', $result->errors[1]->getPrevious());
|
||||
|
||||
$this->assertEquals(
|
||||
'GraphQL Interface Type `Pet` returned `null` from it`s `resolveType` function for value: '.
|
||||
@ -105,13 +105,6 @@ class AbstractTest extends \PHPUnit_Framework_TestCase
|
||||
'all possible implementations. It degrades query performance significantly. '.
|
||||
'Make sure your `resolveType` always returns valid implementation or throws.',
|
||||
$result->errors[0]->getMessage());
|
||||
|
||||
$this->assertEquals(
|
||||
'GraphQL Interface Type `Pet` returned `null` from it`s `resolveType` function for value: '.
|
||||
'instance of GraphQL\Tests\Executor\Cat. Switching to slow resolution method using `isTypeOf` of '.
|
||||
'all possible implementations. It degrades query performance significantly. '.
|
||||
'Make sure your `resolveType` always returns valid implementation or throws.',
|
||||
$result->errors[1]->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user