mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-03-12 15:56:06 +03:00
Expose original type configs for custom app-level metadata
This commit is contained in:
parent
98e5835620
commit
cc6c6a14f5
@ -28,6 +28,11 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
|||||||
*/
|
*/
|
||||||
private $_resolveTypeFn;
|
private $_resolveTypeFn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the interfaces to know about this implementation.
|
* Update the interfaces to know about this implementation.
|
||||||
* This is an rare and unfortunate use of mutation in the type definition
|
* This is an rare and unfortunate use of mutation in the type definition
|
||||||
@ -60,6 +65,7 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
|
|||||||
$this->description = isset($config['description']) ? $config['description'] : null;
|
$this->description = isset($config['description']) ? $config['description'] : null;
|
||||||
$this->_fields = !empty($config['fields']) ? FieldDefinition::createMap($config['fields']) : [];
|
$this->_fields = !empty($config['fields']) ? FieldDefinition::createMap($config['fields']) : [];
|
||||||
$this->_resolveTypeFn = isset($config['resolveType']) ? $config['resolveType'] : null;
|
$this->_resolveTypeFn = isset($config['resolveType']) ? $config['resolveType'] : null;
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,11 +58,11 @@ class ObjectType extends Type implements OutputType, CompositeType
|
|||||||
private $_isTypeOf;
|
private $_isTypeOf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeping reference of config for late bindings
|
* Keeping reference of config for late bindings and custom app-level metadata
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $_config;
|
public $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var callable
|
* @var callable
|
||||||
@ -93,7 +93,7 @@ class ObjectType extends Type implements OutputType, CompositeType
|
|||||||
$this->description = isset($config['description']) ? $config['description'] : null;
|
$this->description = isset($config['description']) ? $config['description'] : null;
|
||||||
$this->resolveFieldFn = isset($config['resolveField']) ? $config['resolveField'] : null;
|
$this->resolveFieldFn = isset($config['resolveField']) ? $config['resolveField'] : null;
|
||||||
$this->_isTypeOf = isset($config['isTypeOf']) ? $config['isTypeOf'] : null;
|
$this->_isTypeOf = isset($config['isTypeOf']) ? $config['isTypeOf'] : null;
|
||||||
$this->_config = $config;
|
$this->config = $config;
|
||||||
|
|
||||||
if (isset($config['interfaces'])) {
|
if (isset($config['interfaces'])) {
|
||||||
InterfaceType::addImplementationToInterfaces($this);
|
InterfaceType::addImplementationToInterfaces($this);
|
||||||
@ -106,7 +106,7 @@ class ObjectType extends Type implements OutputType, CompositeType
|
|||||||
public function getFields()
|
public function getFields()
|
||||||
{
|
{
|
||||||
if (null === $this->_fields) {
|
if (null === $this->_fields) {
|
||||||
$fields = isset($this->_config['fields']) ? $this->_config['fields'] : [];
|
$fields = isset($this->config['fields']) ? $this->config['fields'] : [];
|
||||||
$fields = is_callable($fields) ? call_user_func($fields) : $fields;
|
$fields = is_callable($fields) ? call_user_func($fields) : $fields;
|
||||||
$this->_fields = FieldDefinition::createMap($fields);
|
$this->_fields = FieldDefinition::createMap($fields);
|
||||||
}
|
}
|
||||||
@ -133,13 +133,22 @@ class ObjectType extends Type implements OutputType, CompositeType
|
|||||||
public function getInterfaces()
|
public function getInterfaces()
|
||||||
{
|
{
|
||||||
if (null === $this->_interfaces) {
|
if (null === $this->_interfaces) {
|
||||||
$interfaces = isset($this->_config['interfaces']) ? $this->_config['interfaces'] : [];
|
$interfaces = isset($this->config['interfaces']) ? $this->config['interfaces'] : [];
|
||||||
$interfaces = is_callable($interfaces) ? call_user_func($interfaces) : $interfaces;
|
$interfaces = is_callable($interfaces) ? call_user_func($interfaces) : $interfaces;
|
||||||
$this->_interfaces = $interfaces;
|
$this->_interfaces = $interfaces;
|
||||||
}
|
}
|
||||||
return $this->_interfaces;
|
return $this->_interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param InterfaceType $iface
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function implementsInterface(InterfaceType $iface)
|
||||||
|
{
|
||||||
|
return !!Utils::find($this->getInterfaces(), function($implemented) use ($iface) {return $iface === $implemented;});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user