title: How to implement auto refresh token in graphql for jwt based authentication?
body: <p>I am trying to figure out this scenario for my JWT based authentication in Apollo based graphql server <strong>(2.0)</strong> .</p>
  
  <p>Basically after login a user gets accessToken and refreshToken from server.</p>
  
  <p>AccessToken gets expired after certain period of time and server sends an error message indicating that token expired (<strong>TokenExpiredError</strong>) and then client need to communicate with server for new accessToken via passing refreshToken.</p>
  
  <p>Flow is as following -</p>
  
  <ol>
  <li><strong>TokenExpiredError</strong> occurs</li>
  <li>Get that error on client side</li>
  <li>Queue all requests with old accessToken(so that server is not flooded with too many refreshToken calls and many accessTokens are generated by server)</li>
  <li>Call refreshToken api on graphql server to get new accessToken</li>
  <li>update accessToken for all authorised calls with new accessToken</li>
  <li>Logout user incase refreshToken itself is expired</li>
  <li>Prevent any kind of race condition b/w calls</li>
  </ol>
  
  <p>I have already implemented refreshToken mutation on client side but can't figure out about when error occurs stop all requests -> request new token ->  make all pending request again and if refresh token is expired logout user.</p>