Skip to content

Commit 197c2d3

Browse files
committed
Allow thunks for Union possible types + preserve original type config with Union (for custom user-land definitions)
1 parent 5f2b237 commit 197c2d3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Type/Definition/UnionType.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ class UnionType extends Type implements AbstractType, OutputType, CompositeType
2020
*/
2121
private $_resolveType;
2222

23+
/**
24+
* @var array
25+
*/
26+
private $_config;
27+
2328
public function __construct($config)
2429
{
2530
Config::validate($config, [
2631
'name' => Config::STRING | Config::REQUIRED,
27-
'types' => Config::arrayOf(Config::OBJECT_TYPE | Config::REQUIRED),
32+
'types' => Config::arrayOf(Config::OBJECT_TYPE, Config::REQUIRED),
2833
'resolveType' => Config::CALLBACK, // function($value, ResolveInfo $info) => ObjectType
2934
'description' => Config::STRING
3035
]);
@@ -40,13 +45,17 @@ public function __construct($config)
4045
$this->description = isset($config['description']) ? $config['description'] : null;
4146
$this->_types = $config['types'];
4247
$this->_resolveType = isset($config['resolveType']) ? $config['resolveType'] : null;
48+
$this->_config = $config;
4349
}
4450

4551
/**
4652
* @return array<ObjectType>
4753
*/
4854
public function getPossibleTypes()
4955
{
56+
if ($this->_types instanceof \Closure) {
57+
$this->_types = call_user_func($this->_types);
58+
}
5059
return $this->_types;
5160
}
5261

0 commit comments

Comments
 (0)