Novak Djokovic showed phenomenal defence as he somehow prevailed in an epic rally with Taylor Fritz at the Shanghai Open.