mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 04:46:04 +03:00
Deprecated GraphQL\Type\Definition\Config
(#148)
This commit is contained in:
parent
ed3591c1a9
commit
6845b28a35
@ -6,19 +6,14 @@ require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
use \GraphQL\Examples\Blog\Types;
|
||||
use \GraphQL\Examples\Blog\AppContext;
|
||||
use \GraphQL\Examples\Blog\Data\DataSource;
|
||||
use \GraphQL\Schema;
|
||||
use \GraphQL\Type\Schema;
|
||||
use \GraphQL\GraphQL;
|
||||
use \GraphQL\Type\Definition\Config;
|
||||
use \GraphQL\Error\FormattedError;
|
||||
|
||||
// Disable default PHP error reporting - we have better one for debug mode (see bellow)
|
||||
ini_set('display_errors', 0);
|
||||
|
||||
if (!empty($_GET['debug'])) {
|
||||
// Enable additional validation of type configs
|
||||
// (disabled by default because it is costly)
|
||||
Config::enableValidation();
|
||||
|
||||
// Catch custom errors (to report them in query results if debugging is enabled)
|
||||
$phpErrors = [];
|
||||
set_error_handler(function($severity, $message, $file, $line) use (&$phpErrors) {
|
||||
|
@ -7,8 +7,9 @@ final class Warning
|
||||
const ASSIGN_WARNING = 2;
|
||||
const CONFIG_WARNING = 4;
|
||||
const RESOLVE_TYPE_WARNING = 8;
|
||||
const CONFIG_DEPRECATION_WARNING = 16;
|
||||
|
||||
const ALL = 7;
|
||||
const ALL = 23;
|
||||
|
||||
static $enableWarnings = self::ALL;
|
||||
|
||||
@ -45,24 +46,24 @@ final class Warning
|
||||
}
|
||||
}
|
||||
|
||||
static function warnOnce($errorMessage, $warningId)
|
||||
static function warnOnce($errorMessage, $warningId, $messageLevel = null)
|
||||
{
|
||||
if (self::$warningHandler) {
|
||||
$fn = self::$warningHandler;
|
||||
$fn($errorMessage, $warningId);
|
||||
} else if ((self::$enableWarnings & $warningId) > 0 && !isset(self::$warned[$warningId])) {
|
||||
self::$warned[$warningId] = true;
|
||||
trigger_error($errorMessage, E_USER_WARNING);
|
||||
trigger_error($errorMessage, $messageLevel ?: E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
static function warn($errorMessage, $warningId)
|
||||
static function warn($errorMessage, $warningId, $messageLevel = null)
|
||||
{
|
||||
if (self::$warningHandler) {
|
||||
$fn = self::$warningHandler;
|
||||
$fn($errorMessage, $warningId);
|
||||
} else if ((self::$enableWarnings & $warningId) > 0) {
|
||||
trigger_error($errorMessage, E_USER_WARNING);
|
||||
trigger_error($errorMessage, $messageLevel ?: E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,13 @@ class Config
|
||||
*/
|
||||
public static function enableValidation($allowCustomOptions = true)
|
||||
{
|
||||
Warning::warnOnce(
|
||||
'GraphQL\Type\Defintion\Config is deprecated and will be removed in the next version. ' .
|
||||
'See https://github.com/webonyx/graphql-php/issues/148 for alternatives',
|
||||
Warning::CONFIG_DEPRECATION_WARNING,
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
self::$enableValidation = true;
|
||||
self::$allowCustomOptions = $allowCustomOptions;
|
||||
}
|
||||
|
@ -128,9 +128,9 @@ class FieldDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|Config $fields
|
||||
* @param array $fields
|
||||
* @param string $parentTypeName
|
||||
* @deprecated
|
||||
* @deprecated use defineFieldMap instead
|
||||
* @return array
|
||||
*/
|
||||
public static function createMap(array $fields, $parentTypeName = null)
|
||||
|
@ -3,8 +3,7 @@ namespace GraphQL\Tests\Executor;
|
||||
|
||||
use GraphQL\Executor\Executor;
|
||||
use GraphQL\Language\Parser;
|
||||
use GraphQL\Schema;
|
||||
use GraphQL\Type\Definition\Config;
|
||||
use GraphQL\Type\Schema;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
|
||||
|
@ -7,8 +7,7 @@ use GraphQL\Error\Warning;
|
||||
use GraphQL\Executor\Executor;
|
||||
use GraphQL\GraphQL;
|
||||
use GraphQL\Language\Parser;
|
||||
use GraphQL\Schema;
|
||||
use GraphQL\Type\Definition\Config;
|
||||
use GraphQL\Type\Schema;
|
||||
use GraphQL\Type\Definition\InterfaceType;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ResolveInfo;
|
||||
|
@ -12,6 +12,11 @@ use GraphQL\Utils\Utils;
|
||||
|
||||
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
\PHPUnit_Framework_Error_Deprecated::$enabled = false;
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
Config::disableValidation();
|
||||
|
@ -3,8 +3,7 @@ namespace GraphQL\Tests\Type;
|
||||
|
||||
require_once __DIR__ . '/TestClasses.php';
|
||||
|
||||
use GraphQL\Schema;
|
||||
use GraphQL\Type\Definition\Config;
|
||||
use GraphQL\Type\Schema;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use GraphQL\Type\Definition\InterfaceType;
|
||||
@ -496,20 +495,18 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->inputObjectType
|
||||
];
|
||||
|
||||
// TODO: extract config validation to separate test
|
||||
Config::enableValidation();
|
||||
foreach ($badUnionTypes as $type) {
|
||||
try {
|
||||
new UnionType(['name' => 'BadUnion', 'types' => [$type]]);
|
||||
$union = new UnionType(['name' => 'BadUnion', 'types' => [$type]]);
|
||||
$union->assertValid();
|
||||
$this->fail('Expected exception not thrown');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertSame(
|
||||
'Error in "BadUnion" type definition: expecting "ObjectType definition" at "types:0", but got "' . Utils::getVariableType($type) . '"',
|
||||
'BadUnion may only contain Object types, it cannot contain: ' . Utils::printSafe($type) . '.',
|
||||
$e->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
Config::disableValidation();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,6 @@
|
||||
namespace GraphQL\Tests\Type;
|
||||
|
||||
use GraphQL\Error\InvariantViolation;
|
||||
use GraphQL\Type\Definition\Config;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use GraphQL\Type\Definition\InterfaceType;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
@ -83,8 +82,6 @@ class ResolutionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Config::enableValidation(false);
|
||||
|
||||
$this->node = new InterfaceType([
|
||||
'name' => 'Node',
|
||||
'fields' => [
|
||||
|
@ -3,7 +3,6 @@ namespace GraphQL\Tests\Type;
|
||||
|
||||
use GraphQL\Error\InvariantViolation;
|
||||
use GraphQL\Error\Warning;
|
||||
use GraphQL\Type\Definition\Config;
|
||||
use GraphQL\Type\Schema;
|
||||
use GraphQL\Type\Definition\CustomScalarType;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
@ -42,8 +41,6 @@ class ValidationTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Config::disableValidation();
|
||||
|
||||
$this->String = 'TestString';
|
||||
|
||||
$this->SomeScalarType = new CustomScalarType([
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Utils;
|
||||
|
||||
use GraphQL\Type\Definition\Config;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use GraphQL\Type\Definition\InterfaceType;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
@ -81,8 +80,6 @@ class ExtractTypesTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Config::enableValidation(false);
|
||||
|
||||
$this->node = new InterfaceType([
|
||||
'name' => 'Node',
|
||||
'fields' => [
|
||||
|
Loading…
Reference in New Issue
Block a user