Infer type name from className for enum and scalar types as well

This commit is contained in:
vladar 2016-10-24 16:46:21 +07:00
parent f9740c5f2c
commit 19436c326d
2 changed files with 8 additions and 0 deletions

View File

@ -27,6 +27,10 @@ class EnumType extends Type implements InputType, OutputType, LeafType
public function __construct($config) public function __construct($config)
{ {
if (!isset($config['name'])) {
$config['name'] = $this->tryInferName();
}
Config::validate($config, [ Config::validate($config, [
'name' => Config::STRING | Config::REQUIRED, 'name' => Config::STRING | Config::REQUIRED,
'values' => Config::arrayOf([ 'values' => Config::arrayOf([

View File

@ -28,6 +28,10 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp
*/ */
public function __construct() public function __construct()
{ {
if (!isset($this->name)) {
$this->name = $this->tryInferName();
}
Utils::invariant($this->name, 'Type must be named.'); Utils::invariant($this->name, 'Type must be named.');
} }