Automattic\WooCommerce\Vendor\GraphQL\Type\Definition
InputObjectType::initializeField
Method of the class: InputObjectType{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->initializeField( $nameOrIndex, $field ): void;
- $nameOrIndex(string|int) (required)
- .
- $field(required)
- .
InputObjectType::initializeField() InputObjectType::initializeField code WC 11.1.2
protected function initializeField($nameOrIndex, $field): void
{
if (is_callable($field)) {
$field = $field();
}
assert($field instanceof Type || is_array($field) || $field instanceof InputObjectField);
if ($field instanceof Type) {
$field = ['type' => $field];
}
assert(is_array($field) || $field instanceof InputObjectField); // @phpstan-ignore-line TODO remove when using actual union types
if (is_array($field)) {
$field['name'] ??= $nameOrIndex;
if (! is_string($field['name'])) {
throw new InvariantViolation("{$this->name} fields must be an associative array with field names as keys, an array of arrays with a name attribute, or a callable which returns one of those.");
}
$field = new InputObjectField($field); // @phpstan-ignore-line array type is wrongly inferred
}
assert($field instanceof InputObjectField); // @phpstan-ignore-line TODO remove when using actual union types
$this->fields[$field->name] = $field;
}