protected function getSuggestedTypeNames(Schema $schema, TypeInterface $type, string $fieldName): array
    {
        if (!$type instanceof AbstractTypeInterface) {
            // Otherwise, must be an Object type, which does not have possible fields.
            return [];
        }

        $suggestedObjectTypes = [];
        $interfaceUsageCount  = [];

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

            $typeFields = $possibleType->getFields();

            if (!isset($typeFields[$fieldName])) {
                break;
            }

            if (!$possibleType instanceof NamedTypeInterface) {
                continue;
            }

            $suggestedObjectTypes[] = $possibleType->getName();

            if (!$possibleType instanceof ObjectType) {
                continue;
            }

            foreach ($possibleType->getInterfaces() as $possibleInterface) {
                $interfaceFields = $possibleInterface->getFields();

                if (!isset($interfaceFields[$fieldName])) {
                    break;
                }

                $interfaceName                       = $possibleInterface->getName();
                $interfaceUsageCount[$interfaceName] = ($interfaceUsageCount[$interfaceName] ?? 0) + 1;
            }
        }

        $suggestedInterfaceTypes = \array_keys($interfaceUsageCount);

        \uasort($suggestedInterfaceTypes, function ($a, $b) use ($interfaceUsageCount) {
            return $interfaceUsageCount[$b] - $interfaceUsageCount[$a];
        });

        return \array_merge($suggestedInterfaceTypes, $suggestedObjectTypes);
    }
protected function getSuggestedTypeNames(Schema $schema, TypeInterface $type, string $fieldName): array
    {
        if (!$type instanceof AbstractTypeInterface) {
            // Otherwise, must be an Object type, which does not have possible fields.
            return [];
        }

        $suggestedObjectTypes = [];
        $interfaceUsageCount  = [];

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

            $typeFields = $possibleType->getFields();

            if (!isset($typeFields[$fieldName])) {
                break;
            }

            if (!$possibleType instanceof NamedTypeInterface) {
                continue;
            }

            $suggestedObjectTypes[] = $possibleType->getName();

            if (!$possibleType instanceof ObjectType) {
                continue;
            }

            foreach ($possibleType->getInterfaces() as $possibleInterface) {
                $interfaceFields = $possibleInterface->getFields();

                if (!isset($interfaceFields[$fieldName])) {
                    break;
                }

                $interfaceName                       = $possibleInterface->getName();
                $interfaceUsageCount[$interfaceName] = ($interfaceUsageCount[$interfaceName] ?? 0) + 1;
            }
        }

        $suggestedInterfaceTypes = \array_keys($interfaceUsageCount);

        \uasort($suggestedInterfaceTypes, function ($a, $b) use ($interfaceUsageCount) {
            return $interfaceUsageCount[$b] - $interfaceUsageCount[$a];
        });

        return \array_merge($suggestedInterfaceTypes, $suggestedObjectTypes);
    }
protected function getSuggestedTypeNames ( Schema $ schema , TypeInterface $ type , string $ fieldName ) : array { if ( ! $ type instanceof AbstractTypeInterface ) { // Otherwise, must be an Object type, which does not have possible fields. return [ ] ; } $ suggestedObjectTypes = [ ] ; $ interfaceUsageCount = [ ] ; foreach ( $ schema -> getPossibleTypes ( $ type ) as $ possibleType ) { if ( ! $ possibleType instanceof FieldsAwareInterface ) { continue ; } $ typeFields = $ possibleType -> getFields ( ) ; if ( ! isset ( $ typeFields [ $ fieldName ] ) ) { break ; } if ( ! $ possibleType instanceof NamedTypeInterface ) { continue ; } $ suggestedObjectTypes [ ] = $ possibleType -> getName ( ) ; if ( ! $ possibleType instanceof ObjectType ) { continue ; } foreach ( $ possibleType -> getInterfaces ( ) as $ possibleInterface ) { $ interfaceFields = $ possibleInterface -> getFields ( ) ; if ( ! isset ( $ interfaceFields [ $ fieldName ] ) ) { break ; } $ interfaceName = $ possibleInterface -> getName ( ) ; $ interfaceUsageCount [ $ interfaceName ] = ( $ interfaceUsageCount [ $ interfaceName ] ?? 0 ) + 1 ; } } $ suggestedInterfaceTypes = \ array_keys ( $ interfaceUsageCount ) ; \ uasort ( $ suggestedInterfaceTypes , function ( $ a , $ b ) use ( $ interfaceUsageCount ) { return $ interfaceUsageCount [ $ b ] - $ interfaceUsageCount [ $ a ] ; } ) ; return \ array_merge ( $ suggestedInterfaceTypes , $ suggestedObjectTypes ) ; }
Go through all of the implementations of type, as well as the interfaces
that they implement. If any of those types include the provided field,
suggest them, sorted by how often the type is referenced,  starting
with Interfaces.

@param Schema        $schema
@param TypeInterface $type
@param string        $fieldName
@return array
@throws InvariantException
Go through all of the implementations of type as well as the interfaces that they implement . If any of those types include the provided field suggest them sorted by how often the type is referenced starting with Interfaces .