Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

FieldsOnCorrectType::getSuggestedTypeNamesprotectedWC 1.0

Go through all implementations of a type, as well as the interfaces that it implements. If any of those types include the provided field, suggest them, sorted by how often the type is referenced, starting with interfaces.

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

Хуков нет.

Возвращает

Массив. string>

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->getSuggestedTypeNames( $schema, $type, $fieldName ): array;
$schema(Schema) (обязательный)
.
$type(Type) (обязательный)
.
$fieldName(строка) (обязательный)
.

Код FieldsOnCorrectType::getSuggestedTypeNames() WC 10.9.1

protected function getSuggestedTypeNames(Schema $schema, Type $type, string $fieldName): array
{
    if (Type::isAbstractType($type)) {
        $suggestedObjectTypes = [];
        $interfaceUsageCount = [];

        foreach ($schema->getPossibleTypes($type) as $possibleType) {
            if (! $possibleType->hasField($fieldName)) {
                continue;
            }

            // This object type defines this field.
            $suggestedObjectTypes[] = $possibleType->name;
            foreach ($possibleType->getInterfaces() as $possibleInterface) {
                if (! $possibleInterface->hasField($fieldName)) {
                    continue;
                }

                // This interface type defines this field.
                $interfaceUsageCount[$possibleInterface->name] = isset($interfaceUsageCount[$possibleInterface->name])
                    ? $interfaceUsageCount[$possibleInterface->name] + 1
                    : 0;
            }
        }

        // Suggest interface types based on how common they are.
        arsort($interfaceUsageCount);
        $suggestedInterfaceTypes = array_keys($interfaceUsageCount);

        // Suggest both interface and object types.
        return array_merge($suggestedInterfaceTypes, $suggestedObjectTypes);
    }

    // Otherwise, must be an Object type, which does not have suggested types.
    return [];
}