In this talk, I will summarize several recent results about gravitational wave cosmology in the context of dark energy and inflation. In the first part of the talk, I will concentrate on astrophysical gravitational waves and will argue that the spatial clustering of gravitational wave sources provides a wealth of invaluable information concerning the propagation law of gravitational waves. I will demonstrate its importance for constraining deviations from General Relativity on cosmological scales. In the second part of the talk, I will discuss gravitational waves produced during inflation and will revisit the implications of their possible near-future detection for inflationary models. I will particularly present our proposal of resonant gravitational wave production during inflation due to non-linear effects and will discuss the implications for the well-known Lyth bound. I will also present related ideas for producing induced gravitational waves and primordial black holes on small scales.