title: How to use helper functions with Apollo GraphQL
body: <p>I find myself in situations with React/Redux apps where I require a lot of functions to transform data when it comes back from the server by using libaries like moment or jwtDecode. For example:</p>
  
  <pre><code>function mapDispatchToProps(dispatch) {
      return {
          getAllTokens: () =&gt; {
              dispatch(getAllTokens());
          }
      };
  }
  </code></pre>
  
  <p>On page load, I run <code>this.props.getAllTokens()</code> to bring back all tokens from the server stored in the database which I'd like to show on the page (for example).</p>
  
  <p>The dispatch uses Redux Thunk to perform some operations on the data and send to the store:</p>
  
  <pre><code>export const getAllTokens = () =&gt; dispatch =&gt; {
      apiGetAllUsers()
          .then(tokens =&gt; {
              let newFormat = tokens.message.map(token =&gt; {
                  if (token.refreshToken) {
                      let decoded = jwtDecode(token.refreshToken);
                      let expiresIn = moment.unix(decoded.exp).fromNow();
  
                      return {
                          refreshToken: token.refreshToken,
                          email: token.email,
                          expiresIn
                      };
                  }
              });
              dispatch(adminTokensReceived(newFormat));
          })
  };
  </code></pre>
  
  <p>This function <code>getAllTokens</code> is in another file to help the component keep lean. This approach works fine for Redux, but when it comes to using Apollo instead, how would I update the data before adding it back to the component props?</p>
  
  <p>I have came across <a href="https://www.apollographql.com/docs/react/basics/queries.html#graphql-props-option" rel="nofollow noreferrer">this link</a> which shows how to update data from a query, but I don't see many examples using it, so I wondered if I'm missing something fundamental?</p>
  
  <p>So my questions is, what is the best way to use helper functions as I've described above? </p>
  
  <p>Thanks</p>