From 19436c326d00889fd4afcf99bbbe056cc2113269 Mon Sep 17 00:00:00 2001 From: vladar Date: Mon, 24 Oct 2016 16:46:21 +0700 Subject: [PATCH] Infer type name from className for enum and scalar types as well --- src/Type/Definition/EnumType.php | 4 ++++ src/Type/Definition/ScalarType.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Type/Definition/EnumType.php b/src/Type/Definition/EnumType.php index 3e2fd64..cb71a91 100644 --- a/src/Type/Definition/EnumType.php +++ b/src/Type/Definition/EnumType.php @@ -27,6 +27,10 @@ class EnumType extends Type implements InputType, OutputType, LeafType public function __construct($config) { + if (!isset($config['name'])) { + $config['name'] = $this->tryInferName(); + } + Config::validate($config, [ 'name' => Config::STRING | Config::REQUIRED, 'values' => Config::arrayOf([ diff --git a/src/Type/Definition/ScalarType.php b/src/Type/Definition/ScalarType.php index 25515de..9b9a5a5 100644 --- a/src/Type/Definition/ScalarType.php +++ b/src/Type/Definition/ScalarType.php @@ -28,6 +28,10 @@ abstract class ScalarType extends Type implements OutputType, InputType, LeafTyp */ public function __construct() { + if (!isset($this->name)) { + $this->name = $this->tryInferName(); + } + Utils::invariant($this->name, 'Type must be named.'); }