1414 * @phpstan-type EagerFieldConfig InputObjectField|(Type&InputType)|UnnamedInputObjectFieldConfig
1515 * @phpstan-type LazyFieldConfig callable(): EagerFieldConfig
1616 * @phpstan-type FieldConfig EagerFieldConfig|LazyFieldConfig
17+ * @phpstan-type ParseValueFn callable(array<string, mixed>): mixed
1718 * @phpstan-type InputObjectConfig array{
1819 * name?: string|null,
1920 * description?: string|null,
2021 * fields: iterable<FieldConfig>|callable(): iterable<FieldConfig>,
21- * parseValue?: callable(array<string, mixed>): mixed ,
22+ * parseValue?: ParseValueFn|null ,
2223 * astNode?: InputObjectTypeDefinitionNode|null,
2324 * extensionASTNodes?: array<InputObjectTypeExtensionNode>|null
2425 * }
@@ -27,6 +28,16 @@ class InputObjectType extends Type implements InputType, NullableType, NamedType
2728{
2829 use NamedTypeImplementation;
2930
31+ /**
32+ * Lazily initialized.
33+ *
34+ * @var array<string, InputObjectField>
35+ */
36+ private array $ fields ;
37+
38+ /** @var ParseValueFn|null */
39+ private $ parseValue ;
40+
3041 public ?InputObjectTypeDefinitionNode $ astNode ;
3142
3243 /** @var array<InputObjectTypeExtensionNode> */
@@ -35,13 +46,6 @@ class InputObjectType extends Type implements InputType, NullableType, NamedType
3546 /** @phpstan-var InputObjectConfig */
3647 public array $ config ;
3748
38- /**
39- * Lazily initialized.
40- *
41- * @var array<string, InputObjectField>
42- */
43- private array $ fields ;
44-
4549 /**
4650 * @throws InvariantViolation
4751 *
@@ -53,6 +57,8 @@ public function __construct(array $config)
5357 {
5458 $ this ->name = $ config ['name ' ] ?? $ this ->inferName ();
5559 $ this ->description = $ config ['description ' ] ?? null ;
60+ // $this->fields is initialized lazily
61+ $ this ->parseValue = $ config ['parseValue ' ] ?? null ;
5662 $ this ->astNode = $ config ['astNode ' ] ?? null ;
5763 $ this ->extensionASTNodes = $ config ['extensionASTNodes ' ] ?? [];
5864
@@ -155,23 +161,23 @@ protected function initializeField($nameOrIndex, $field): void
155161 /**
156162 * Parses an externally provided value (query variable) to use as an input.
157163 *
158- * Should throw an exception with a client friendly message on invalid values, @see ClientAware.
164+ * Should throw an exception with a client- friendly message on invalid values, @see ClientAware.
159165 *
160166 * @param array<string, mixed> $value
161167 *
162168 * @return mixed
163169 */
164170 public function parseValue (array $ value )
165171 {
166- if (isset ($ this ->config [ ' parseValue ' ] )) {
167- return $ this ->config [ ' parseValue ' ] ($ value );
172+ if (isset ($ this ->parseValue )) {
173+ return ( $ this ->parseValue ) ($ value );
168174 }
169175
170176 return $ value ;
171177 }
172178
173179 /**
174- * Validates type config and throws if one of type options is invalid.
180+ * Validates type config and throws if one of the type options is invalid.
175181 * Note: this method is shallow, it won't validate object fields and their arguments.
176182 *
177183 * @throws Error
0 commit comments