Automattic\WooCommerce\Vendor\GraphQL\Utils

ASTDefinitionBuilder::internalBuildTypeprivateWC 1.0

Method of the class: ASTDefinitionBuilder{}

No Hooks.

Returns

Type&NamedType.

Usage

// private - for code of main (parent) class only
$result = $this->internalBuildType( $typeName, ?Node $typeNode ): Type;
$typeName(string) (required)
.
?Node $typeNode
.
Default: null

ASTDefinitionBuilder::internalBuildType() code WC 10.9.1

private function internalBuildType(string $typeName, ?Node $typeNode = null): Type
{
    if (isset($this->cache[$typeName])) {
        return $this->cache[$typeName];
    }

    if (isset($this->typeDefinitionsMap[$typeName])) {
        $type = $this->makeSchemaDef($this->typeDefinitionsMap[$typeName]);

        if ($this->typeConfigDecorator !== null) {
            try {
                $config = ($this->typeConfigDecorator)(
                    $type->config,
                    $this->typeDefinitionsMap[$typeName],
                    $this->typeDefinitionsMap
                );
            } catch (\Throwable $e) {
                $class = static::class;
                throw new Error("Type config decorator passed to {$class} threw an error when building {$typeName} type: {$e->getMessage()}", null, null, [], null, $e);
            }

            // @phpstan-ignore-next-line should not happen, but function types are not enforced by PHP
            if (! is_array($config) || isset($config[0])) {
                $class = static::class;
                $notArray = Utils::printSafe($config);
                throw new Error("Type config decorator passed to {$class} is expected to return an array, but got {$notArray}");
            }

            $type = $this->makeSchemaDefFromConfig($this->typeDefinitionsMap[$typeName], $config);
        }

        return $this->cache[$typeName] = $type;
    }

    return $this->cache[$typeName] = ($this->resolveType)($typeName, $typeNode);
}