diff --git a/src/Type/Definition/InterfaceType.php b/src/Type/Definition/InterfaceType.php index 6435e6f..c7e470c 100644 --- a/src/Type/Definition/InterfaceType.php +++ b/src/Type/Definition/InterfaceType.php @@ -28,6 +28,11 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT */ private $_resolveTypeFn; + /** + * @var array + */ + public $config; + /** * Update the interfaces to know about this implementation. * 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->_fields = !empty($config['fields']) ? FieldDefinition::createMap($config['fields']) : []; $this->_resolveTypeFn = isset($config['resolveType']) ? $config['resolveType'] : null; + $this->config = $config; } /** diff --git a/src/Type/Definition/ObjectType.php b/src/Type/Definition/ObjectType.php index 9275820..5fd211b 100644 --- a/src/Type/Definition/ObjectType.php +++ b/src/Type/Definition/ObjectType.php @@ -58,11 +58,11 @@ class ObjectType extends Type implements OutputType, CompositeType private $_isTypeOf; /** - * Keeping reference of config for late bindings + * Keeping reference of config for late bindings and custom app-level metadata * * @var array */ - private $_config; + public $config; /** * @var callable @@ -93,7 +93,7 @@ class ObjectType extends Type implements OutputType, CompositeType $this->description = isset($config['description']) ? $config['description'] : null; $this->resolveFieldFn = isset($config['resolveField']) ? $config['resolveField'] : null; $this->_isTypeOf = isset($config['isTypeOf']) ? $config['isTypeOf'] : null; - $this->_config = $config; + $this->config = $config; if (isset($config['interfaces'])) { InterfaceType::addImplementationToInterfaces($this); @@ -106,7 +106,7 @@ class ObjectType extends Type implements OutputType, CompositeType public function getFields() { 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; $this->_fields = FieldDefinition::createMap($fields); } @@ -133,13 +133,22 @@ class ObjectType extends Type implements OutputType, CompositeType public function getInterfaces() { 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; $this->_interfaces = $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 * @return bool|null