Automattic\WooCommerce\Vendor\GraphQL\Type\Definition

FieldDefinition::assertValidpublicWC 1.0

Method of the class: FieldDefinition{}

No Hooks.

Returns

null. Nothing (null).

Usage

$FieldDefinition = new FieldDefinition();
$FieldDefinition->assertValid( $parentType ): void;
$parentType(Type&NamedType) (required)
.

FieldDefinition::assertValid() code WC 10.9.1

public function assertValid(Type $parentType): void
{
    $error = Utils::isValidNameError($this->name);
    if ($error !== null) {
        throw new InvariantViolation("{$parentType->name}.{$this->name}: {$error->getMessage()}");
    }

    $type = Type::getNamedType($this->getType());

    if (! $type instanceof OutputType) {
        $safeType = Utils::printSafe($this->type);
        throw new InvariantViolation("{$parentType->name}.{$this->name} field type must be Output Type but got: {$safeType}.");
    }

    // @phpstan-ignore-next-line unnecessary according to types, but can happen during runtime
    if ($this->resolveFn !== null && ! is_callable($this->resolveFn)) {
        $safeResolveFn = Utils::printSafe($this->resolveFn);
        throw new InvariantViolation("{$parentType->name}.{$this->name} field resolver must be a function if provided, but got: {$safeResolveFn}.");
    }

    foreach ($this->args as $fieldArgument) {
        $fieldArgument->assertValid($this, $type);
    }
}