From 197c2d3532bf549636cd47eb9aae4d78bd92f090 Mon Sep 17 00:00:00 2001 From: vladar Date: Sat, 17 Oct 2015 17:37:40 +0600 Subject: [PATCH] Allow thunks for Union possible types + preserve original type config with Union (for custom user-land definitions) --- src/Type/Definition/UnionType.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Type/Definition/UnionType.php b/src/Type/Definition/UnionType.php index 527f668..d6151f1 100644 --- a/src/Type/Definition/UnionType.php +++ b/src/Type/Definition/UnionType.php @@ -20,11 +20,16 @@ class UnionType extends Type implements AbstractType, OutputType, CompositeType */ private $_resolveType; + /** + * @var array + */ + private $_config; + public function __construct($config) { Config::validate($config, [ 'name' => Config::STRING | Config::REQUIRED, - 'types' => Config::arrayOf(Config::OBJECT_TYPE | Config::REQUIRED), + 'types' => Config::arrayOf(Config::OBJECT_TYPE, Config::REQUIRED), 'resolveType' => Config::CALLBACK, // function($value, ResolveInfo $info) => ObjectType 'description' => Config::STRING ]); @@ -40,6 +45,7 @@ class UnionType extends Type implements AbstractType, OutputType, CompositeType $this->description = isset($config['description']) ? $config['description'] : null; $this->_types = $config['types']; $this->_resolveType = isset($config['resolveType']) ? $config['resolveType'] : null; + $this->_config = $config; } /** @@ -47,6 +53,9 @@ class UnionType extends Type implements AbstractType, OutputType, CompositeType */ public function getPossibleTypes() { + if ($this->_types instanceof \Closure) { + $this->_types = call_user_func($this->_types); + } return $this->_types; }