<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yohei Kanehara on Medium]]></title>
        <description><![CDATA[Stories by Yohei Kanehara on Medium]]></description>
        <link>https://medium.com/@kanehara?source=rss-1a693e03d923------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4Rr9LFm6xiiZqs-P50kL8Q.jpeg</url>
            <title>Stories by Yohei Kanehara on Medium</title>
            <link>https://medium.com/@kanehara?source=rss-1a693e03d923------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:01:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kanehara/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Our journey of integrating GraphQL into our REST app — learning to swim]]></title>
            <link>https://medium.com/reviewtrackers-engineering/our-journey-of-integrating-graphql-into-our-rest-app-learning-to-swim-d171cbad71c6?source=rss-1a693e03d923------2</link>
            <guid isPermaLink="false">https://medium.com/p/d171cbad71c6</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Yohei Kanehara]]></dc:creator>
            <pubDate>Fri, 06 Dec 2019 15:39:11 GMT</pubDate>
            <atom:updated>2019-12-06T15:40:12.718Z</atom:updated>
            <content:encoded><![CDATA[<h3>Our journey of integrating GraphQL into our REST app — learning to swim</h3><p><em>TL;DR GraphQL is amazing and can be incrementally integrated into a REST app but be wary of the client side cache.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*di7bhLC_gIwXRtEBiOvwSg.png" /></figure><p>The story of GraphQL at ReviewTrackers goes all the way back to our very <a href="https://engineering.reviewtrackers.com/reviewtrackers-hackathon-part-2-hacking-together-a-graphql-server-cab99f9ef305">first Hackathon</a>. What started out as an experimental “hack” project has matured into a production service that now serves our most important page in our application — the reviews page. While plenty of articles and tutorials exist on integrating GraphQL into greenfield applications, there is a lack of resources on integrating GraphQL into existing applications. I’d like to share our journey of integrating GraphQL into our app, both the ups and and downs, so hopefully others can take from our experience when considering to adopt GraphQL. I compare our experience to swimming — incrementally dipping our feet into the pool until we jumped into the deep end…</p><h3>Background: Why GraphQL?</h3><p>At ReviewTrackers, we maintain two applications — a React web application and a React Native mobile application. Both applications interface with our backend through a REST API. As our app grew and our data models became more complex, our client codebases also grew in complexity as it had to fetch and update all this complex data. A lot of our data is also relational — e.g. a review belongs to a location which in turn belongs to an account. This inevitably lead to <a href="https://stackoverflow.com/questions/44564905/what-is-over-fetching-or-under-fetching">over fetching / under fetching</a> issues on our front end which we initially solved with sql views and dedicated REST endpoints for complex, relational data. While this was performant and worked, it was a clunky, time consuming dev experience and didn’t scale well since we’d have to deploy database migrations each time we needed new data and would also tightly couple our client applications to our database model. Not to mention that we’d have to make changes to both our web app and mobile app code bases if there were any breaking changes in the REST API. In short, we found that modern front end applications require a lot of flexibility in how they declare their data requirements — the exact pain point that GraphQL was designed to solve. After a <a href="https://engineering.reviewtrackers.com/reviewtrackers-hackathon-part-2-hacking-together-a-graphql-server-cab99f9ef305">successful hackathon</a> of proving GraphQL’s viability, we started to slowly integrate GraphQL into our application.</p><h3>Incremental adoption</h3><p>At ReviewTrackers, we practice continuous deployment and push to production multiple times a day. This means that any change to our system should be incrementally deployed and not block our deployment pipeline — each deployment should be de-risked and other devs should be able to deploy. This means that a complete rewrite from REST to GraphQL was out of the question. Rewrites in my opinion are also <a href="https://daedtech.com/the-myth-of-the-software-rewrite/">rarely the right solution</a>. So we strategically wanted to integrate GraphQL into our app through a path of least resistance — slowly dipping into the pool. We did this by keeping our interface to our backend consistent by wrapping our REST api in a GraphQL layer rather than interfacing with our database directly. In terms of integrating GraphQL into our client applications, we identified data fetching as the natural first step.</p><h3>Data fetching: getting our feet wet</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FK6Q7ZCdLy8pCE%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FK6Q7ZCdLy8pCE%2Fgiphy-downsized.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FK6Q7ZCdLy8pCE%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a000eac79c5a8057e92736829fd302b/href">https://medium.com/media/2a000eac79c5a8057e92736829fd302b/href</a></iframe><p>Most of our existing components fetched data and subscribed to them through redux like so:</p><pre>const LocationName = ({location, loading, error, fetchLocation, locationID}) =&gt; {  <br>  useEffect(() =&gt; fetchLocation(locationID), [])<br>  if (loading) return &lt;p&gt;Loading...&lt;/p&gt;<br>  if (error) return &lt;p&gt;An error occurred&lt;/p&gt;</pre><pre>  return &lt;h1&gt;{location.name}&lt;/h1&gt;<br>}</pre><pre>connect(<br>  state =&gt; ({ <br>    location: state.resources.location, <br>    error: state.resources.errors.location, <br>    loading: state.resources.loading.location  <br>  }),<br>  dispatch =&gt; ({ <br>    fetchLocation: (id) =&gt; dispatch(fetchLocationAction(id)) <br>  })<br>)(LocationName)</pre><p>This seems like a really nice component since everything is encapsulated into this one component but this type of component can introduce over fetching problems. For example, if we were rendering the component in two parts of the screen, we would be redundantly fetching the same location over the network. To mitigate, we could lift this fetching up to a higher common ancestor. Over time, this strategy made our root container components unruly with multiple resources being fetched, various loading and error states managed in redux, etc. Not to mention that our original component would become disjointed and dependent on another component.</p><blockquote>In short, our components no longer became encapsulated.</blockquote><p>Client side GraphQL libraries like Apollo solve this through a cache layer to prevent over fetching. So in the same scenario where our component is rendered in two parts of the screen, there will only be one trip over the network to retrieve the location which will then be cached and reused when another request for the location is fired. This allows us to build the encapsulated version of our component like so:</p><pre>const GET_LOCATION_NAME = gql`<br>  query GetLocationName($locationID: ID!) {<br>    location(id: $locationID) { <br>      name <br>    }<br>  }<br>`</pre><pre>const LocationName = ({locationID}) =&gt; {  <br>  const {data, error, loading} = useQuery(<br>    GET_LOCATION_NAME, { variables: { locationID } }<br>  )<br>  if (loading) return &lt;p&gt;Loading...&lt;/p&gt;<br>  if (error) return &lt;p&gt;An error occurred&lt;/p&gt;</pre><pre>return &lt;h1&gt;{location.name}&lt;/h1&gt;<br>}</pre><p>Personally, I love this style of building data rich components. The loading and error states along with the data fetched are all encapsulated in a react hook. As long as we kept our data shape the same, we could migrate our redux / REST based components to GraphQL — amazing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*gw-ijoG3OP0K28_rm8r95A.gif" /><figcaption>The GraphQL hype is real</figcaption></figure><blockquote>While we were stoked, the client side cache actually ended up biting us in more nuanced scenarios…</blockquote><h3>The reviews page: going swimming</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fr6ALgGVKLg93O%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fr6ALgGVKLg93O%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fr6ALgGVKLg93O%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7ed71ced55aafb67ab9568d77b31cd4/href">https://medium.com/media/e7ed71ced55aafb67ab9568d77b31cd4/href</a></iframe><p>We continued getting our feet wet with GraphQL by migrating less risky components to GraphQL. Everything was going smoothly when a bigger use case for GraphQL arose when we decided to refactor our reviews page to be more performant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uo1cw4C46WuygY0Pp3RF7A.png" /><figcaption>The reviews page</figcaption></figure><p>As a review tracking application, the reviews page is crucial to our users. As our company grew, so did our data which lead to performance issues for accounts with large review volumes. We tried <a href="https://engineering.reviewtrackers.com/speeding-up-our-api-with-redis-a47736278511">tuning it with Redis</a> in the past but eventually realized we would need to implement a <a href="https://engineering.reviewtrackers.com/the-100-million-row-dash-9e888539df51">new cursor based API</a> to reap the biggest performance boost.</p><p>Cursor based pagination is <a href="https://graphql.org/learn/pagination/#pagination-and-edges">the recommended way to paginate in GraphQL</a> and we knew we’d have to implement this new API in both our web app and mobile app so we took this as an opportunity to implement this in GraphQL. It was the perfect fit!</p><p>After a few weeks of hard work, we rolled out the first version of the new reviews page (web only) behind a feature flag to a small subset of our customers. The results were tremendous with our largest accounts loading <strong>~1900% faster</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZADuUgFrSeGjptISugGt6Q.gif" /><figcaption>Side by side comparison (5x speed)</figcaption></figure><p>It wasn’t without some hiccups though…</p><h3>The client side cache: jumping into the deep end</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FieZe796AFlVMk%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FieZe796AFlVMk%2Fgiphy-downsized.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FieZe796AFlVMk%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="238" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f99ea4332318b2f75a8f711c4e9653f/href">https://medium.com/media/7f99ea4332318b2f75a8f711c4e9653f/href</a></iframe><p>Remember that client side cache? It was amazing and worked so well that some users complained the page was unresponsive when changing filters — a result of cached reviews causing the page to load too fast. We were stoked about how well this worked until we noticed some weird things…</p><p>When users would update a review status in the review detail page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Y8jHq4W8YAAlg4EwSzCpg.png" /></figure><p>They noticed it would not reflect on the reviews page without a page refresh:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mwBb5kM5vu1Ib2o_8gzhlA.png" /></figure><p>It turns out that our GraphQL cache is not updated when the POST request to update the review status is fired, causing this stale cache issue.</p><p>Sad 😞</p><p>To fix this, we updated the review status dropdown to also be driven by GraphQL so the client cache would be updated. This worked and we were able to still reap the benefits of the client side cache 😎.</p><p>Until we realized the same issue occurred when adding tags to reviews…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yzj85lA2g-pU_CqAHN6akA.png" /></figure><p>And when responding to reviews…</p><p>And basically any REST mutation not going through our GraphQL layer…</p><p>Sad 😞</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FEYmAHLpw5LBbG%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FEYmAHLpw5LBbG%2F200w_d.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FEYmAHLpw5LBbG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c5e6a92a6f2b9dd8d6e5fe4e0fd39cf/href">https://medium.com/media/2c5e6a92a6f2b9dd8d6e5fe4e0fd39cf/href</a></iframe><p>Apollo provides some ways to <a href="https://www.apollographql.com/docs/react/caching/cache-configuration/">manipulate the cache</a> directly, which we initially tried but it turned out too cumbersome and imperative that we backtracked.</p><blockquote>There are only two hard things in Computer Science: cache invalidation and naming things.</blockquote><blockquote>— Phil Karlton</blockquote><p>We ultimately ended up backtracking on the use of the cache entirely by configuring our Apollo client to use the network-only <a href="https://www.apollographql.com/docs/react/api/react-apollo/#optionsfetchpolicy">fetch policy</a> which bypasses the client side cache and fires a network request per query. While we would take a slight performance hit, this tradeoff was worth it to avoid the headaches of cache eviction. We also were only firing the query in a single root component — i.e. multiple components weren’t firing the same query like our LocationName component above. This simple change allowed us to keep our reviews page in sync with any REST mutations, fixing all the stale cache issues above.</p><h3>Configuring the GraphQL client: floatation device</h3><p>We found that configuring and tuning the GraphQL client when integrating GraphQL into a REST application is key — our floatation device 😉.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fetn52ENYVnpxqMaXiT%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fetn52ENYVnpxqMaXiT%2Fgiphy-downsized.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fetn52ENYVnpxqMaXiT%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e8907f601d65afa5fb1837364a90991/href">https://medium.com/media/0e8907f601d65afa5fb1837364a90991/href</a></iframe><p>We configured our Apollo client to default to a cache-and-network fetch policy which returns data from the cache if present but fires a network request in the background to validate the data and update the cache if needed (by default, the Apollo client will skip network requests entirely if data is in the cache).</p><blockquote>This fetch policy optimizes for users getting a quick response while also trying to keep cached data consistent with your server data at the cost of extra network requests.</blockquote><p>You can configure your ApolloClient to achieve this like so:</p><pre>const client = new ApolloClient({<br>  link,<br>  cache,<br>  defaultOptions: {<br>    watchQuery: {<br>      fetchPolicy: &#39;cache-and-network&#39;,<br>      errorPolicy: &#39;all&#39;<br>    },<br>  query: {<br>    fetchPolicy: &#39;cache-and-network&#39;,<br>    errorPolicy: &#39;all&#39;<br>  },<br>  mutate: {<br>    errorPolicy: &#39;all&#39;<br>  }<br>}})</pre><p>Now all our queries will fire network request to revalidate the cache to avoid any issues with mutations occurring outside our GraphQL client. Furthermore, each GraphQL query can be individually configured to use a different network policy if needed — e.g. our reviews page still uses the network-only network policy to make sure we never show stale review data.</p><p>Our newly tuned GraphQL configuration allowed us to successfully integrated GraphQL on both web and mobile clients 🎊. Overall it has been a huge success and produced amazing results barring some hiccups. I have no doubt GraphQL will continue to improve as the community and tooling around it improves.</p><h3>Key takeaways</h3><ul><li>Incrementally adopt GraphQL starting with data fetching</li><li>Have good automated tests to make sure nothing breaks along the way</li><li>Rollout GraphQL migrations incrementally to users</li><li>Configure your GraphQL client to skip the cache or revalidate the cache to avoid stale cache issues**</li></ul><p><em>** More relevant when integrating into an existing REST application</em></p><p>Questions or comments? Find me on Github or email!</p><ul><li><a href="https://github.com/kanehara">Github</a></li><li>kanehara@umich.edu</li></ul><p>Interested in solving challenging problems like this on a well funded, fun team? <a href="https://jobs.lever.co/reviewtrackers">Come work for us!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d171cbad71c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reviewtrackers-engineering/our-journey-of-integrating-graphql-into-our-rest-app-learning-to-swim-d171cbad71c6">Our journey of integrating GraphQL into our REST app — learning to swim</a> was originally published in <a href="https://medium.com/reviewtrackers-engineering">ReviewTrackers Engineering, Product and Design Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RT Hacks II — GraphQL Subscriptions]]></title>
            <link>https://medium.com/reviewtrackers-engineering/rt-hacks-ii-graphql-subscriptions-b11a2c8aac47?source=rss-1a693e03d923------2</link>
            <guid isPermaLink="false">https://medium.com/p/b11a2c8aac47</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[Yohei Kanehara]]></dc:creator>
            <pubDate>Wed, 12 Dec 2018 20:23:10 GMT</pubDate>
            <atom:updated>2018-12-12T23:03:15.396Z</atom:updated>
            <content:encoded><![CDATA[<h3>RT Hacks II — GraphQL Subscriptions</h3><p>Our company held our second Hackathon this past month. Checkout the series on our <a href="https://engineering.reviewtrackers.com/reviewtrackers-hackathon-part-1-4f94d52ee514">first Hackathon</a>.</p><p>During the previous hackathon, we built a <a href="https://engineering.reviewtrackers.com/reviewtrackers-hackathon-part-2-hacking-together-a-graphql-server-cab99f9ef305">GraphQL server</a> to fetch some data from our REST API. I decided to extend this and implement another amazing feature of GraphQL — subscriptions.</p><h3>What are subscriptions?</h3><p><a href="https://graphql.org/blog/subscriptions-in-graphql-and-relay/">Subscriptions</a> allow for GraphQL clients to listen to server side data over a web socket. This enables realtime features without a browser refresh. You could technically accomplish the same thing by implementing a web socket yourself or using a third party tool like <a href="https://pusher.com/">Pusher</a>. However, GraphQL subscriptions have the advantage that it’s built into the GraphQL paradigm and libraries such as Apollo come with great tooling and API’s around them. You also don’t have the overhead of managing web socket messages or having to rely on (or pay 💸) a third party service for real time functionality.</p><blockquote>Subscriptions should be used in areas of an app where users can expect things to happen in real time.</blockquote><h3>How does it work?</h3><p>In our ReviewTrackers app, users can leave notes on reviews for other users. Say I trigger a GraphQL <a href="https://graphql.org/learn/queries/#mutations">mutation</a> client side to update a note on a review, I can then have server side logic to push the updated note to any clients “subscribed” to new notes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*DOjFWMhLFKYa7yEbYOAzFA.png" /></figure><p>As the diagram alludes, if you had multiple client applications (in our case a web app and a mobile app), both clients would receive the update live!</p><h3>Real time notes in action</h3><p>The review notes scenario is exactly what I implemented for the hackathon. In our current application, users would have to refresh the page to see any new notes left on reviews. With GraphQL subscriptions, users can see notes as they come in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*arVzM-cNcHgrQmy34-wjGQ.gif" /><figcaption>Real time notes of 2 different users viewing the same review</figcaption></figure><h3>Notifications</h3><p>You may have noticed the “Notifications” button in the bottom right. That’s because that button is also listening in on the same note subscription!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*j9tUQjoteWzdbMQX1RAqNQ.png" /><figcaption>Real time notifications</figcaption></figure><h3>Dev experience</h3><p>Not only is GraphQL and subscriptions amazing from a product / UX standpoint, it’s also amazing from a developer standpoint. Just look at how simple the API is for a subscription!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*_fow9jaxKDpxq4VYniMlSA.png" /></figure><p>You can even test out and play with subscriptions all within GraphiQL just like queries!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0XRnKB23M2nZ234rNssXxw.gif" /><figcaption>Mutation + subscription tested inside GraphiQL</figcaption></figure><h3>Mutation-less subscriptions</h3><p>Subscriptions are not just limited to reactions to GraphQL mutations. You can push any server side data to a subscription. For example, we use <a href="https://www.rabbitmq.com/">RabbitMQ</a> to handle server side events at ReviewTrackers. We could potentially setup subscriptions to listen to any RabbitMQ event such as new reviews, review status change, etc.</p><h3>Next steps</h3><p>Over two hackathons, our GraphQL server has really matured and handles all the major features of GraphQL — queries, mutations, and subscriptions. We plan on deploying it as a standalone service soon that our web app and mobile app can use.</p><p>Did you enjoy this post? Come join our awesome team! Checkout our job openings <a href="https://www.reviewtrackers.com/company/careers/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b11a2c8aac47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reviewtrackers-engineering/rt-hacks-ii-graphql-subscriptions-b11a2c8aac47">RT Hacks II — GraphQL Subscriptions</a> was originally published in <a href="https://medium.com/reviewtrackers-engineering">ReviewTrackers Engineering, Product and Design Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ReviewTrackers Hackathon: Part 2 — “Hacking” together a GraphQL server]]></title>
            <link>https://medium.com/reviewtrackers-engineering/reviewtrackers-hackathon-part-2-hacking-together-a-graphql-server-cab99f9ef305?source=rss-1a693e03d923------2</link>
            <guid isPermaLink="false">https://medium.com/p/cab99f9ef305</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Yohei Kanehara]]></dc:creator>
            <pubDate>Wed, 02 May 2018 16:05:05 GMT</pubDate>
            <atom:updated>2018-05-22T23:00:00.641Z</atom:updated>
            <content:encoded><![CDATA[<p>This is part 2 of a series of blog posts on the “hacks” of ReviewTrackers’ first <a href="https://en.wikipedia.org/wiki/Hackathon">hackathon</a>. Checkout the first post of the series <a href="https://engineering.reviewtrackers.com/reviewtrackers-hackathon-part-1-4f94d52ee514">here</a>.</p><p>The ReviewTrackers’ app is currently a REST based React app with data fetching and mutations managed via Redux. This is a very common pattern and many apps are built this way.</p><p>On one of my side projects called <a href="http://www.spotimix.com/">Spotimix</a>, I tested out GraphQL and built a GraphQL server over the <a href="https://beta.developer.spotify.com/documentation/web-api/">Spotify Web API</a> (<a href="https://github.com/kanehara/spotimix&#39;">source code</a>). I immediately recognized how much easier and faster I could develop my app when using GraphQL. I no longer had to deal with common boilerplate Redux code for managing my data fetching and mutation. I also recognized common issues that it could solve in the ReviewTrackers’ app — primarily over-fetching and under-fetching <a href="https://stackoverflow.com/questions/44564905/what-is-over-fetching-or-under-fetching">issues</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*r24pQvlK_E7Vogtk." /><figcaption>How it feels to work with REST API’s</figcaption></figure><p>Unfortunately, big architectural undertakings like this would normally have to go through our process of grooming, architecting, investigation, etc. A perfect candidate for a hackathon hack! Our team in 2 days built a GraphQL server over the ReviewTrackers REST API and this is how it went.</p><h3>Day 1 — Scoping, auth, hacking</h3><h4>Scoping</h4><p>Before writing any code, we scoped out our MVP since we only had 2 days of hacking.</p><blockquote>We decided we wanted to demo GraphQL with 3 resources commonly fetched and mutated within our app — reviews, locations, accounts. For our MVP, we decided to solely focus on data fetching and not mutations.</blockquote><p>We thought this would demonstrate GraphQL well since all 3 resources are related to one another (i.e. have “edges” between them).</p><h4>Auth</h4><p>Before fetching any data from our API, we had to configure authentication with our API. We decided to authenticate against our UAT API with one of our internal test users. This actually ended up being one of the most technically difficult pieces of our hack which is a testament to how easy GraphQL is to work with.</p><h4>Hacking</h4><p>Once we had authentication complete, we could start requesting data from our API. For most of the first day, our team group coded the foundation for the GraphQL server. The “driver” (i.e. the typer) would project their screen onto the large monitor in our room while people would give input and suggestions. Our team took turns being the “driver” and it was a great collaborative experience.</p><p>About halfway into the day, we had a simple GraphQL server that served hardcoded dummy data which we could explore with GraphiQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*ZcSSv4iHyLxbDUPYWh0uKw.png" /><figcaption>Exploring our GraphQL server with GraphiQL</figcaption></figure><p>At this point, we also integrated a visualization library called <a href="https://github.com/APIs-guru/graphql-voyager">Voyager</a>. We were pleasantly surprised with how simple it was to setup. This library allowed us to visualize the “graph” of our GraphQL server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2TFeJ5Mmagf90y6Roo4jA.png" /><figcaption>Voyager — A GraphQL visualization library</figcaption></figure><p>For the rest of the day, we split up different resources among devs to flesh out and retrieve real data from our API. By the end of the day, we had about a third of our MVP fleshed out — right on track!</p><h3>Day 2 — Complex queries, polishing, and demo</h3><p>For the second day, we focused on adding nice-to-have’s, polishing our MVP, and organizing our demo. We had our MVP finished by late morning and started working on more complex queries.</p><p>During the demo, we demonstrated several complex queries, highlighted below.</p><h4>Custom resolvers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*_HogbV4sb-QA_45rA1IElg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*GnxYZcgNUQ2STNqTdOqs8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*54_2GMMjMGJI9g4jKVZd8Q.png" /><figcaption>Custom review rating resolvers to return them in 3 different formats</figcaption></figure><h4>Circular query</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXI-fsr06Rr6qpGmnqpj_Q.png" /><figcaption>A query from review -&gt; location -&gt; review</figcaption></figure><h4>Pagination</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bpN0wHi_g9uuD_-UFb1ZNg.gif" /><figcaption>Paginating reviews data for a location</figcaption></figure><h3>Next steps</h3><p>We plan on fleshing out this GraphQL server to eventually be production ready. Our goal is to introduce this into our React Native mobile app first to test it’s feasibility before integrating it into our web app.</p><p>Stay tuned for the final part of the ReviewTrackers Hackathon series that details how a team hacked together a Review counter. You can also checkout part 1 of the series <a href="https://engineering.reviewtrackers.com/reviewtrackers-hackathon-part-1-4f94d52ee514">here</a>.</p><p>Did you enjoy this post? Come join our awesome team! Checkout our job openings <a href="https://www.reviewtrackers.com/company/careers/">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cab99f9ef305" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reviewtrackers-engineering/reviewtrackers-hackathon-part-2-hacking-together-a-graphql-server-cab99f9ef305">ReviewTrackers Hackathon: Part 2 — “Hacking” together a GraphQL server</a> was originally published in <a href="https://medium.com/reviewtrackers-engineering">ReviewTrackers Engineering, Product and Design Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upgrading a production React app by 2 major versions]]></title>
            <link>https://medium.com/reviewtrackers-engineering/upgrading-a-production-react-app-by-2-major-versions-bd52a14f87fd?source=rss-1a693e03d923------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd52a14f87fd</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reviewtrackers]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[upgrade]]></category>
            <dc:creator><![CDATA[Yohei Kanehara]]></dc:creator>
            <pubDate>Mon, 05 Mar 2018 20:03:29 GMT</pubDate>
            <atom:updated>2018-03-05T20:14:20.835Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*iV3MWgtVaOvqPlHSI4HU0w.gif" /></figure><p>At <a href="https://www.reviewtrackers.com/">ReviewTrackers</a>, we maintain a React app with a plethora of public and private npm modules —147 dependencies at the time of writing. Approximately 20 of those dependencies are <a href="https://nodejs.org/en/blog/npm/peer-dependencies/">peer dependent</a> on React.</p><p>With the rapid pace of modern web development, the ReviewTrackers app fell behind as new versions of React were released. Our app was on version 0.14.6 while the latest React release at the time was 16.2.0.</p><p>When I joined the ReviewTrackers engineering team, I identified this as a major concern. Luckily, our engineering culture allows for new engineers to make immediate impact and I was given the opportunity to spearhead our React upgrade. Unfortunately, we didn’t have a fairy godmother to wave a wand and magically upgrade our app so we had a lot of work ahead of us.</p><h3>Challenges</h3><ul><li>Our team practices <a href="https://en.wikipedia.org/wiki/Continuous_delivery">continuous deployment</a>. Coming up with a strategy to not block our deployment pipeline would be crucial.</li><li>Several public and internal npm dependencies were peer dependent on React which would also need upgrading.</li><li>At the time of writing, ReviewTrackers had over 30,000 users. We had to ensure the upgrade goes virtually unnoticed by our users.</li><li>Avoiding a massive pull request containing all the changes</li></ul><h3>The upgrade journey</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*fldFUIsjwYVd00ZaaBWv0w.png" /></figure><p>The overall upgrade strategy was to identify changes that could be React 0.14.x and 16.x compatible so we could isolate and deploy these changes independently.</p><h4>prop-types</h4><p>One of the <a href="https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes">breaking changes</a> introduced in React 15.5 was the breakout of React.PropTypes to it’s own package prop-types. Luckily, React version 0.14.9 is a 0.14.x compatible React that introduces this breaking change to ease migration. We decided to tackle this first and use this <a href="https://github.com/reactjs/react-codemod#react-proptypes-to-prop-types">codemod</a> to update our usages of React.PropTypes.</p><pre>jscodeshift -t react-codemod/transforms/React-PropTypes-to-prop-types.js &lt;path&gt;</pre><p>The codemod virtually updated all of our React components. This was a large change set but since prop type validation is a dev tool, we were confident our e2e tests would catch any regressions.</p><blockquote>Once we had passing e2e tests, we rolled this change out to production.</blockquote><h4>Create a stable upgrade branch</h4><p>We then created a branch off of master to introduce the actual React upgrade. This branch would be our reference point for the changes that would be needed for the upgrade. The main priority on this branch was to get an upgraded version of our app to a stable state.</p><p>The first step was to get a passing test suite. This mostly involved <a href="https://reactjs.org/blog/2017/04/07/react-v15.5.0.html#react-test-utils">migrating</a> react-addons-test-utils and upgrading enzyme(<a href="https://github.com/airbnb/enzyme">a React test utility</a>). Once we had a passing test suite, we ran our webpack bundler. <em>This threw a lot of errors related to broken npm dependencies…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*3kdHQHU9rIZGTbl2k2bcfw.jpeg" /></figure><h4>Upgrading dependencies</h4><p>This was by far the most challenging part of the upgrade. We had over a dozen dependencies that were peer dependent on React. Many of these were critical user facing React components. Even worse, some of these dependencies were poorly maintained and didn’t have releases to support newer versions of React.</p><p>First, we identified the well maintained dependencies that could be upgraded. Of these dependencies, we identified the dependencies that were React 16.x <strong>and</strong> 0.14.x compatible. This way we could validate these upgrades with our e2e tests and deploy these upgraded packages independently from the React upgrade.</p><blockquote>Once we had passing e2e tests, we rolled this change out to production.</blockquote><p>Notice a pattern?</p><p>For the poorly maintained dependencies, we identified:</p><ol><li>How many usages of the dependency exists within our app</li><li>Could we remove any dependencies and write our own code in it’s place?</li></ol><p>We identified a couple open source React components that were used sparingly and could be rewritten ourselves. When rewriting these components we also kept it compatible with React 0.14.x. This allowed us again to deploy these changes independently of the upgrade.</p><blockquote>Once we had passing e2e tests, we rolled this change out to production.</blockquote><p>For dependencies too difficult to rewrite, we took the path of forking the open source code. This involved forking a total of 3 dependencies. Once again, we identified forked packages that were 0.14.x and 16.x compatible and deployed these separately from the React upgrade.</p><blockquote>Once we had passing e2e tests, we rolled this change out to production.</blockquote><h4>Finishing touches</h4><p>After all of these changes, our upgrade branch was in a stable state and could bundle our app without errors. We just needed to add a few finishing touches to our upgrade branch — bug fixes, design tweaks, e2e test updates.</p><p>After adding these finishing touches, we were ready to merge our upgrade branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*8Awqj1IpwuLO0EUdXsGenQ.gif" /></figure><p>The final merge consisted of:</p><ol><li>77 changed files</li><li>3900 changed lines</li><li>2500 deleted lines</li><li>34 upgraded dependencies</li></ol><p>This change set may seem large but doesn’t even include all of the changes we broke out. We were actually pretty happy with how slimmed down we were able to get the final merge considering how large of an upgrade we were undertaking. And you guessed it,</p><blockquote>Once we had passing e2e tests, we rolled this change out to production.</blockquote><h3>Results</h3><p>The rollout was very successful with:</p><ol><li>No rollbacks 💯</li><li>&lt; 5 bugs, all non-critical</li><li>No users reporting issues related to the upgrade</li></ol><h3>Unlocked super powers</h3><p>The successful React upgrade unlocked some awesome new features shipped in React that we couldn’t use before. The key ones being:</p><ol><li><a href="https://www.youtube.com/watch?v=ZCuYPiUIONs&amp;index=5&amp;t=0s&amp;list=PLb0IAmt7-GS3fZ46IGFirdqKTIxlws7e0">React Fiber</a></li><li><a href="https://facebook.github.io/jest/docs/en/snapshot-testing.html">Jest snapshot testing</a></li><li><a href="https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html">Error boundaries</a></li><li><a href="https://facebook.github.io/jest/docs/en/snapshot-testing.html">Improved stack traces</a></li></ol><h3>Lessons learned</h3><p>The React upgrade was a huge undertaking and we learned the following lessons:</p><ol><li><strong>Continuous deployment is great</strong>. Continuous deployment allowed us to break out deployable changes needed for the upgrade and deploy them separately.</li><li><strong>Bring the same mindset of continuous deployment for dependencies</strong>. Upgrade dependencies (especially critical ones) often. Smaller, incremental upgrades are much easier to maintain and test. The yarn outdated <a href="https://yarnpkg.com/lang/en/docs/cli/outdated/">command</a> is your friend.</li><li><strong>Prune, prune, prune</strong>. Keep dependencies lean and learn to say no to new dependencies. Every added dependency is a payment. The form of payment being increased bundle size and app maintenance.</li><li><strong>Good e2e tests can save your butt</strong>. This upgrade would not have been possible without our e2e test suite. Otherwise, we would have been manually testing all of our changes — yuck.</li></ol><h3>TL;DR</h3><p>Massive upgrades suck. Upgrade your dependencies often. Breakout changes into as many deployable chunks as possible. Upgrade and maintain dependencies often. Have good e2e coverage. New tech is awesome and keeps devs happy 😃.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd52a14f87fd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/reviewtrackers-engineering/upgrading-a-production-react-app-by-2-major-versions-bd52a14f87fd">Upgrading a production React app by 2 major versions</a> was originally published in <a href="https://medium.com/reviewtrackers-engineering">ReviewTrackers Engineering, Product and Design Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>