public function fetchFromManager($class, Manager $manager, $mode = self::PREFER_UNION)
    {
        if (!in_array($mode, [self::PREFER_UNION, self::PREFER_SINGLE])) {
            throw new InvalidArgumentException(sprintf(
                '%s::%s illegal mode %s. Allowed modes are PREFER_UNION, PREFER_SINGLE',
                __CLASS__,
                __FUNCTION__,
                $mode
            ));
        }
        $typeName = $this->typeNameForDataObject($class);
        $inheritanceTypeName = $this->inheritanceTypeNameForDataObject($class);
        $names = $mode === self::PREFER_UNION
            ? [$inheritanceTypeName, $typeName]
            : [$typeName, $inheritanceTypeName];

        foreach ($names as $type) {
            if ($manager->hasType($type)) {
                return $manager->getType($type);
            }
        }

        throw new InvalidArgumentException(sprintf(
            'The class %s could not be resolved to any type in the manager instance.',
            $class
        ));
    }