mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-24 22:06:04 +03:00
Allow thunks for Union possible types + preserve original type config with Union (for custom user-land definitions)
This commit is contained in:
parent
5f2b2376e0
commit
197c2d3532
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user