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

            foreach ($schema->getPossibleTypes($type) as $possibleType) {
                $fields = $possibleType->getFields();
                if (! isset($fields[$fieldName])) {
                    continue;
                }
                // This object type defines this field.
                $suggestedObjectTypes[] = $possibleType->name;
                foreach ($possibleType->getInterfaces() as $possibleInterface) {
                    $fields = $possibleInterface->getFields();
                    if (! isset($fields[$fieldName])) {
                        continue;
                    }
                    // This interface type defines this field.
                    $interfaceUsageCount[$possibleInterface->name] =
                        ! isset($interfaceUsageCount[$possibleInterface->name])
                            ? 0
                            : $interfaceUsageCount[$possibleInterface->name] + 1;
                }
            }

            // 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 possible fields.
        return [];
    }
private function getSuggestedTypeNames(Schema $schema, $type, $fieldName)
    {
        if (Type::isAbstractType($type)) {
            $suggestedObjectTypes = [];
            $interfaceUsageCount  = [];

            foreach ($schema->getPossibleTypes($type) as $possibleType) {
                $fields = $possibleType->getFields();
                if (! isset($fields[$fieldName])) {
                    continue;
                }
                // This object type defines this field.
                $suggestedObjectTypes[] = $possibleType->name;
                foreach ($possibleType->getInterfaces() as $possibleInterface) {
                    $fields = $possibleInterface->getFields();
                    if (! isset($fields[$fieldName])) {
                        continue;
                    }
                    // This interface type defines this field.
                    $interfaceUsageCount[$possibleInterface->name] =
                        ! isset($interfaceUsageCount[$possibleInterface->name])
                            ? 0
                            : $interfaceUsageCount[$possibleInterface->name] + 1;
                }
            }

            // 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 possible fields.
        return [];
    }
private function getSuggestedTypeNames ( Schema $ schema , $ type , $ fieldName ) { if ( Type :: isAbstractType ( $ type ) ) { $ suggestedObjectTypes = [ ] ; $ interfaceUsageCount = [ ] ; foreach ( $ schema -> getPossibleTypes ( $ type ) as $ possibleType ) { $ fields = $ possibleType -> getFields ( ) ; if ( ! isset ( $ fields [ $ fieldName ] ) ) { continue ; } // This object type defines this field. $ suggestedObjectTypes [ ] = $ possibleType -> name ; foreach ( $ possibleType -> getInterfaces ( ) as $ possibleInterface ) { $ fields = $ possibleInterface -> getFields ( ) ; if ( ! isset ( $ fields [ $ fieldName ] ) ) { continue ; } // This interface type defines this field. $ interfaceUsageCount [ $ possibleInterface -> name ] = ! isset ( $ interfaceUsageCount [ $ possibleInterface -> name ] ) ? 0 : $ interfaceUsageCount [ $ possibleInterface -> name ] + 1 ; } } // 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 possible fields. return [ ] ; }
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 ObjectType|InterfaceType $type
@param string                   $fieldName

@return string[]
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 .