A compact all-in-line graphene-based distributed feedback Bragg-grating fiber laser (GDFB-FL) with narrow linewidth of hundreds kHz is demonstrated and investigated in this study. Performing as an optical saturable absorber, graphene oscillates the initially kHz linewidth DFB-FL, and generates high-quality passively Q-switched pulses. Pumped with a 980 nm continuous-wave laser, the Q-switched GDFB-FL observes ~1 μs pulse durations, with pulse energies up to ~10 nJ and approaching the transform limit. The peak power is ~600 times higher than the original DFB-FL laser. By optimizing the cavity design and the graphene material, it is predicted that fast Q-switched pulses with more than MHz repetition rates and sub-100 ns pulse durations are achievable. Such transform-limited Q-switched GDFB-FLs with narrow linewidth of sub-MHz have long coherence length, good tunability, stability, compactness and robustness, with potential impact in optical coherent communications, metrology and sensing.