Automattic\WooCommerce\Vendor\GraphQL\Type

Schema::getTypeMappublicWC 1.0

Returns all types in this schema.

This operation requires a full schema scan. Do not use in production environment.

Method of the class: Schema{}

No Hooks.

Returns

Array. Type&NamedType> Keys represent type names, values are instances of corresponding type definitions

Usage

$Schema = new Schema();
$Schema->getTypeMap(): array;

Schema::getTypeMap() code WC 10.9.4

public function getTypeMap(): array
{
    if (! $this->fullyLoaded) {
        // Reset order of user provided types, since calls to getType() may have loaded them
        $this->resolvedTypes = [];

        $scalarOverrides = $this->getScalarOverrides();

        foreach ($this->materializeTypes() as $typeOrLazyType) {
            /** @var Type|callable(): Type $typeOrLazyType */
            $type = self::resolveType($typeOrLazyType);
            assert($type instanceof NamedType);

            /** @var string $typeName Necessary assertion for PHPStan + PHP 8.2 */
            $typeName = $type->name;

            if (isset($scalarOverrides[$typeName])) {
                continue;
            }

            assert(
                ! isset($this->resolvedTypes[$typeName]) || $type === $this->resolvedTypes[$typeName],
                "Schema must contain unique named types but contains multiple types named \"{$type}\" (see https://webonyx.github.io/graphql-php/type-definitions/#type-registry).",
            );

            $this->resolvedTypes[$typeName] = $type;
        }

        // To preserve order of user-provided types, we add first to add them to
        // the set of "collected" types, so `collectReferencedTypes` ignore them.
        /** @var array<string, Type&NamedType> $allReferencedTypes */
        $allReferencedTypes = [];
        foreach ($this->resolvedTypes as $type) {
            // When we ready to process this type, we remove it from "collected" types
            // and then add it together with all dependent types in the correct position.
            unset($allReferencedTypes[$type->name]);
            TypeInfo::extractTypes($type, $allReferencedTypes);
        }

        foreach ([$this->getQueryType(), $this->getMutationType(), $this->getSubscriptionType()] as $rootType) {
            if ($rootType instanceof ObjectType) {
                TypeInfo::extractTypes($rootType, $allReferencedTypes);
            }
        }

        foreach ($this->getDirectives() as $directive) {
            // @phpstan-ignore-next-line generics are not strictly enforceable, error will be caught during schema validation
            if ($directive instanceof Directive) {
                TypeInfo::extractTypesFromDirectives($directive, $allReferencedTypes);
            }
        }
        TypeInfo::extractTypes(Introspection::_schema(), $allReferencedTypes);

        // Apply scalar overrides after all extractions, replacing the
        // global singletons with user-provided instances.
        foreach ($scalarOverrides as $name => $override) {
            $allReferencedTypes[$name] = $override;
        }

        $this->resolvedTypes = $allReferencedTypes;
        $this->fullyLoaded = true;
    }

    return $this->resolvedTypes;
}