Skip to content

Commit cc6c6a1

Browse files
committed
Expose original type configs for custom app-level metadata
1 parent 98e5835 commit cc6c6a1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/Type/Definition/InterfaceType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
2828
*/
2929
private $_resolveTypeFn;
3030

31+
/**
32+
* @var array
33+
*/
34+
public $config;
35+
3136
/**
3237
* Update the interfaces to know about this implementation.
3338
* This is an rare and unfortunate use of mutation in the type definition
@@ -60,6 +65,7 @@ public function __construct(array $config)
6065
$this->description = isset($config['description']) ? $config['description'] : null;
6166
$this->_fields = !empty($config['fields']) ? FieldDefinition::createMap($config['fields']) : [];
6267
$this->_resolveTypeFn = isset($config['resolveType']) ? $config['resolveType'] : null;
68+
$this->config = $config;
6369
}
6470

6571
/**

src/Type/Definition/ObjectType.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ class ObjectType extends Type implements OutputType, CompositeType
5858
private $_isTypeOf;
5959

6060
/**
61-
* Keeping reference of config for late bindings
61+
* Keeping reference of config for late bindings and custom app-level metadata
6262
*
6363
* @var array
6464
*/
65-
private $_config;
65+
public $config;
6666

6767
/**
6868
* @var callable
@@ -93,7 +93,7 @@ public function __construct(array $config)
9393
$this->description = isset($config['description']) ? $config['description'] : null;
9494
$this->resolveFieldFn = isset($config['resolveField']) ? $config['resolveField'] : null;
9595
$this->_isTypeOf = isset($config['isTypeOf']) ? $config['isTypeOf'] : null;
96-
$this->_config = $config;
96+
$this->config = $config;
9797

9898
if (isset($config['interfaces'])) {
9999
InterfaceType::addImplementationToInterfaces($this);
@@ -106,7 +106,7 @@ public function __construct(array $config)
106106
public function getFields()
107107
{
108108
if (null === $this->_fields) {
109-
$fields = isset($this->_config['fields']) ? $this->_config['fields'] : [];
109+
$fields = isset($this->config['fields']) ? $this->config['fields'] : [];
110110
$fields = is_callable($fields) ? call_user_func($fields) : $fields;
111111
$this->_fields = FieldDefinition::createMap($fields);
112112
}
@@ -133,13 +133,22 @@ public function getField($name)
133133
public function getInterfaces()
134134
{
135135
if (null === $this->_interfaces) {
136-
$interfaces = isset($this->_config['interfaces']) ? $this->_config['interfaces'] : [];
136+
$interfaces = isset($this->config['interfaces']) ? $this->config['interfaces'] : [];
137137
$interfaces = is_callable($interfaces) ? call_user_func($interfaces) : $interfaces;
138138
$this->_interfaces = $interfaces;
139139
}
140140
return $this->_interfaces;
141141
}
142142

143+
/**
144+
* @param InterfaceType $iface
145+
* @return bool
146+
*/
147+
public function implementsInterface(InterfaceType $iface)
148+
{
149+
return !!Utils::find($this->getInterfaces(), function($implemented) use ($iface) {return $iface === $implemented;});
150+
}
151+
143152
/**
144153
* @param $value
145154
* @return bool|null

0 commit comments

Comments
 (0)