Skip to content

Commit 0e11cd0

Browse files
committed
Consistently assign configuration values to properties in InputObjectType
1 parent 10fc7f1 commit 0e11cd0

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/Type/Definition/InputObjectType.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
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

src/Type/Definition/LeafType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function serialize($value);
3131
/**
3232
* Parses an externally provided value (query variable) to use as an input.
3333
*
34-
* Should throw an exception with a client friendly message on invalid values, @see ClientAware.
34+
* Should throw an exception with a client-friendly message on invalid values, @see ClientAware.
3535
*
3636
* @param mixed $value
3737
*
@@ -44,7 +44,7 @@ public function parseValue($value);
4444
/**
4545
* Parses an externally provided literal value (hardcoded in GraphQL query) to use as an input.
4646
*
47-
* Should throw an exception with a client friendly message on invalid value nodes, @see ClientAware.
47+
* Should throw an exception with a client-friendly message on invalid value nodes, @see ClientAware.
4848
*
4949
* @param ValueNode&Node $valueNode
5050
* @param array<string, mixed>|null $variables

src/Type/Definition/ObjectType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function isTypeOf($objectValue, $context, ResolveInfo $info)
143143
}
144144

145145
/**
146-
* Validates type config and throws if one of type options is invalid.
146+
* Validates type config and throws if one of the type options is invalid.
147147
* Note: this method is shallow, it won't validate object fields and their arguments.
148148
*
149149
* @throws Error

0 commit comments

Comments
 (0)