14
14
* @phpstan-type EagerFieldConfig InputObjectField|(Type&InputType)|UnnamedInputObjectFieldConfig
15
15
* @phpstan-type LazyFieldConfig callable(): EagerFieldConfig
16
16
* @phpstan-type FieldConfig EagerFieldConfig|LazyFieldConfig
17
+ * @phpstan-type ParseValueFn callable(array<string, mixed>): mixed
17
18
* @phpstan-type InputObjectConfig array{
18
19
* name?: string|null,
19
20
* description?: string|null,
20
21
* fields: iterable<FieldConfig>|callable(): iterable<FieldConfig>,
21
- * parseValue?: callable(array<string, mixed>): mixed ,
22
+ * parseValue?: ParseValueFn|null ,
22
23
* astNode?: InputObjectTypeDefinitionNode|null,
23
24
* extensionASTNodes?: array<InputObjectTypeExtensionNode>|null
24
25
* }
@@ -27,6 +28,16 @@ class InputObjectType extends Type implements InputType, NullableType, NamedType
27
28
{
28
29
use NamedTypeImplementation;
29
30
31
+ /**
32
+ * Lazily initialized.
33
+ *
34
+ * @var array<string, InputObjectField>
35
+ */
36
+ private array $ fields ;
37
+
38
+ /** @var ParseValueFn|null */
39
+ private $ parseValue ;
40
+
30
41
public ?InputObjectTypeDefinitionNode $ astNode ;
31
42
32
43
/** @var array<InputObjectTypeExtensionNode> */
@@ -35,13 +46,6 @@ class InputObjectType extends Type implements InputType, NullableType, NamedType
35
46
/** @phpstan-var InputObjectConfig */
36
47
public array $ config ;
37
48
38
- /**
39
- * Lazily initialized.
40
- *
41
- * @var array<string, InputObjectField>
42
- */
43
- private array $ fields ;
44
-
45
49
/**
46
50
* @throws InvariantViolation
47
51
*
@@ -53,6 +57,8 @@ public function __construct(array $config)
53
57
{
54
58
$ this ->name = $ config ['name ' ] ?? $ this ->inferName ();
55
59
$ this ->description = $ config ['description ' ] ?? null ;
60
+ // $this->fields is initialized lazily
61
+ $ this ->parseValue = $ config ['parseValue ' ] ?? null ;
56
62
$ this ->astNode = $ config ['astNode ' ] ?? null ;
57
63
$ this ->extensionASTNodes = $ config ['extensionASTNodes ' ] ?? [];
58
64
@@ -155,23 +161,23 @@ protected function initializeField($nameOrIndex, $field): void
155
161
/**
156
162
* Parses an externally provided value (query variable) to use as an input.
157
163
*
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.
159
165
*
160
166
* @param array<string, mixed> $value
161
167
*
162
168
* @return mixed
163
169
*/
164
170
public function parseValue (array $ value )
165
171
{
166
- if (isset ($ this ->config [ ' parseValue ' ] )) {
167
- return $ this ->config [ ' parseValue ' ] ($ value );
172
+ if (isset ($ this ->parseValue )) {
173
+ return ( $ this ->parseValue ) ($ value );
168
174
}
169
175
170
176
return $ value ;
171
177
}
172
178
173
179
/**
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.
175
181
* Note: this method is shallow, it won't validate object fields and their arguments.
176
182
*
177
183
* @throws Error
0 commit comments