Automattic\WooCommerce\Vendor\GraphQL\Type

Introspection::_typepublic staticWC 1.0

Метод класса: Introspection{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = Introspection::_type(): ObjectType;

Код Introspection::_type() WC 10.9.1

public static function _type(): ObjectType
{
    return self::$cachedInstances[self::TYPE_OBJECT_NAME] ??= new ObjectType([ // @phpstan-ignore missingType.checkedException (static configuration is known to be correct)
        'name' => self::TYPE_OBJECT_NAME,
        'isIntrospection' => true,
        'description' => 'The fundamental unit of any Automattic\WooCommerce\Vendor\GraphQL Schema is the type. There are '
            . 'many kinds of types in Automattic\WooCommerce\Vendor\GraphQL as represented by the `__TypeKind` enum.'
            . "\n\n"
            . 'Depending on the kind of a type, certain fields describe '
            . 'information about that type. Scalar types provide no information '
            . 'beyond a name and description, while Enum types provide their values. '
            . 'Object and Interface types provide the fields they describe. Abstract '
            . 'types, Union and Interface, provide the Object types possible '
            . 'at runtime. List and NonNull types compose other types.',
        'fields' => static fn (): array => [
            'kind' => [
                'type' => Type::nonNull(self::_typeKind()),
                'resolve' => static function (Type $type): string {
                    switch (true) {
                        case $type instanceof ListOfType:
                            return TypeKind::LIST;
                        case $type instanceof NonNull:
                            return TypeKind::NON_NULL;
                        case $type instanceof ScalarType:
                            return TypeKind::SCALAR;
                        case $type instanceof ObjectType:
                            return TypeKind::OBJECT;
                        case $type instanceof EnumType:
                            return TypeKind::ENUM;
                        case $type instanceof InputObjectType:
                            return TypeKind::INPUT_OBJECT;
                        case $type instanceof InterfaceType:
                            return TypeKind::INTERFACE;
                        case $type instanceof UnionType:
                            return TypeKind::UNION;
                        default:
                            $safeType = Utils::printSafe($type);
                            throw new \Exception("Unknown kind of type: {$safeType}");
                    }
                },
            ],
            'name' => [
                'type' => Type::string(),
                'resolve' => static fn (Type $type): ?string => $type instanceof NamedType
                    ? $type->name
                    : null,
            ],
            'description' => [
                'type' => Type::string(),
                'resolve' => static fn (Type $type): ?string => $type instanceof NamedType
                    ? $type->description
                    : null,
            ],
            'fields' => [
                'type' => Type::listOf(Type::nonNull(self::_field())),
                'args' => [
                    'includeDeprecated' => [
                        'type' => Type::nonNull(Type::boolean()),
                        'defaultValue' => false,
                    ],
                ],
                'resolve' => static function (Type $type, $args): ?array {
                    if ($type instanceof ObjectType || $type instanceof InterfaceType) {
                        $fields = $type->getVisibleFields();

                        if (! $args['includeDeprecated']) {
                            return array_filter(
                                $fields,
                                static fn (FieldDefinition $field): bool => ! $field->isDeprecated()
                            );
                        }

                        return $fields;
                    }

                    return null;
                },
            ],
            'interfaces' => [
                'type' => Type::listOf(Type::nonNull(self::_type())),
                'resolve' => static fn ($type): ?array => $type instanceof ObjectType || $type instanceof InterfaceType
                    ? $type->getInterfaces()
                    : null,
            ],
            'possibleTypes' => [
                'type' => Type::listOf(Type::nonNull(self::_type())),
                'resolve' => static fn ($type, $args, $context, ResolveInfo $info): ?array => $type instanceof InterfaceType || $type instanceof UnionType
                    ? $info->schema->getPossibleTypes($type)
                    : null,
            ],
            'enumValues' => [
                'type' => Type::listOf(Type::nonNull(self::_enumValue())),
                'args' => [
                    'includeDeprecated' => [
                        'type' => Type::nonNull(Type::boolean()),
                        'defaultValue' => false,
                    ],
                ],
                'resolve' => static function ($type, $args): ?array {
                    if ($type instanceof EnumType) {
                        $values = $type->getValues();

                        if (! $args['includeDeprecated']) {
                            return array_filter(
                                $values,
                                static fn (EnumValueDefinition $value): bool => ! $value->isDeprecated()
                            );
                        }

                        return $values;
                    }

                    return null;
                },
            ],
            'inputFields' => [
                'type' => Type::listOf(Type::nonNull(self::_inputValue())),
                'args' => [
                    'includeDeprecated' => [
                        'type' => Type::nonNull(Type::boolean()),
                        'defaultValue' => false,
                    ],
                ],
                'resolve' => static function ($type, $args): ?array {
                    if ($type instanceof InputObjectType) {
                        $fields = $type->getFields();

                        if (! $args['includeDeprecated']) {
                            return array_filter(
                                $fields,
                                static fn (InputObjectField $field): bool => ! $field->isDeprecated(),
                            );
                        }

                        return $fields;
                    }

                    return null;
                },
            ],
            'ofType' => [
                'type' => self::_type(),
                'resolve' => static fn ($type): ?Type => $type instanceof WrappingType
                    ? $type->getWrappedType()
                    : null,
            ],
            'isOneOf' => [
                'type' => Type::boolean(),
                'resolve' => static fn ($type): ?bool => $type instanceof InputObjectType
                    ? $type->isOneOf()
                    : null,
            ],
        ],
    ]);
}