title: Apollo graphql mutation polling with react hooks
body: <p>I have a mutation which I use to login on my application. I want to rerun that login mutation every 5 minutes to check for updates to their profile. <code>useQuery</code> has a <code>pollingInterval</code> options but <code>useMutation</code> does not.</p>
  <p>I tried using a hook to run the mutation on an interval but that doesn't really work because the useAuth hook is used in multiple components at the same time so it ends up creating an interval for each component.</p>
  <pre><code>function useInterval(callback: () =&gt; any, delay: number | null) {
    const savedCallback = useRef&lt;any&gt;();
    useEffect(() =&gt; {
      savedCallback.current = callback;
    }, [callback]);
    useEffect(() =&gt; {
      function tick() {
        savedCallback.current();
      }
      if (delay !== null) {
        const id = setInterval(tick, delay);
        return () =&gt; clearInterval(id);
      }
    }, [delay]);
  }
  
  
  function useAuth(){
    const [login,{data:loginData} = useMutation(gql`
     ...
    `);
  
    useInterval(() =&gt; login(Cookies.get(TOKEN_NAME),1000*60*5);
  
    return login;
  }
  
  function App(){
   const login = useAuth();
   useEffect(() =&gt; {
     login(Cookies.get(TOKEN_NAME));
   },[login]);
  
   ...
  }
  
  </code></pre>