Automattic\WooCommerce\Vendor\GraphQL\Type

SchemaValidationContext::validateInputFieldsprivateWC 1.0

Method of the class: SchemaValidationContext{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->validateInputFields( $inputObj ): void;
$inputObj(InputObjectType) (required)
.

SchemaValidationContext::validateInputFields() code WC 10.9.1

private function validateInputFields(InputObjectType $inputObj): void
{
    $fieldMap = $inputObj->getFields();

    if ($fieldMap === []) {
        $this->reportError(
            "Input Object type {$inputObj->name} must define one or more fields.",
            $this->getAllNodes($inputObj)
        );
    }

    // Ensure the arguments are valid
    foreach ($fieldMap as $fieldName => $field) {
        // Ensure they are named correctly.
        $this->validateName($field);

        // TODO: Ensure they are unique per field.

        // Ensure the type is an input type.
        $type = $field->getType();
        // @phpstan-ignore-next-line The generic type says this should not happen, but a user may use it wrong nonetheless
        if (! Type::isInputType($type)) {
            $notInputType = Utils::printSafe($type);
            $this->reportError(
                "The type of {$inputObj->name}.{$fieldName} must be Input Type but got: {$notInputType}.",
                $field->astNode->type ?? null
            );
        }

        // Ensure valid directives
        if (isset($field->astNode, $field->astNode->directives)) {
            $this->validateDirectivesAtLocation(
                $field->astNode->directives,
                DirectiveLocation::INPUT_FIELD_DEFINITION
            );
        }
    }
}