Automattic\WooCommerce\Vendor\GraphQL\Type\Definition

Type::overrideStandardTypespublic staticWC 1.0

Deprecated. It is no longer supported and may be removed in future releases. See SchemaConfig::$types} or {@see SchemaConfig::$typeLoader}.

Allows partially or completely overriding the standard types globally.

Method of the class: Type{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = Type::overrideStandardTypes( $types ): void;
$types(array) (required)
.

Changelog

Deprecated prefer per-schema scalar overrides via {@see SchemaConfig::$types} or {@see SchemaConfig::$typeLoader}

Type::overrideStandardTypes() code WC 10.9.4

public static function overrideStandardTypes(array $types): void
{
    // Reset caches that might contain instances of built-in scalars
    static::$builtInTypes = null;
    Introspection::resetCachedInstances();
    Directive::resetCachedInstances();

    foreach ($types as $type) {
        // @phpstan-ignore-next-line generic type is not enforced by PHP
        if (! $type instanceof ScalarType) {
            $typeClass = ScalarType::class;
            $notType = Utils::printSafe($type);
            throw new InvariantViolation("Expecting instance of {$typeClass}, got {$notType}");
        }

        if (! self::isBuiltInScalarName($type->name)) {
            $standardTypeNames = implode(', ', self::BUILT_IN_SCALAR_NAMES);
            $notStandardTypeName = Utils::printSafe($type->name);
            throw new InvariantViolation("Expecting one of the following names for a standard type: {$standardTypeNames}; got {$notStandardTypeName}");
        }

        static::$builtInScalars[$type->name] = $type;
    }
}