<?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 Neele Barthel on Medium]]></title>
        <description><![CDATA[Stories by Neele Barthel on Medium]]></description>
        <link>https://medium.com/@helloneele?source=rss-3f1172321468------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*h9ZAwQ_-xmpH9w9H3FX0rQ.png</url>
            <title>Stories by Neele Barthel on Medium</title>
            <link>https://medium.com/@helloneele?source=rss-3f1172321468------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:00:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@helloneele/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[Successfully porting complex data-driven frontends to React with GraphQL]]></title>
            <link>https://levelup.gitconnected.com/successfully-porting-complex-data-driven-frontends-to-react-w-graphql-83a011da5a2a?source=rss-3f1172321468------2</link>
            <guid isPermaLink="false">https://medium.com/p/83a011da5a2a</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[project-planning]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Neele Barthel]]></dc:creator>
            <pubDate>Fri, 17 Jan 2020 19:52:41 GMT</pubDate>
            <atom:updated>2020-01-18T14:52:35.423Z</atom:updated>
            <content:encoded><![CDATA[<p>When porting existing code to React, there is a couple of things to look out for. This article shares my experience while porting a section of a Rails app to React and consuming data through GraphQL.</p><h3>Build context, assess what you are porting</h3><p>If you are familiar with the section you’ll be porting, that’s great. However, even though you have worked on that specific code previously, there might still be hidden functionality you are not aware of.</p><p>In my case, I was not familiar with the specific section of the project that I was porting. This meant that I had to build up a lot of context on the functionality, different features, and possible states a user could be in when using that section.</p><p>A few questions that helped to get a high-level overview and figure out the key aspects of the page were:</p><ul><li><strong>Purpose:</strong> What is this page used for? Why do users go to this page?</li><li><strong>Actions:</strong> What are common workflows for users?</li><li><strong>States:</strong> Which different states can the user who interacts with this page be in? Is there an empty state? What if a user doesn’t have the right permissions or the page just errors?</li><li><strong>Content:</strong> Which data do we need?</li><li><strong>Features:</strong> Are there features that are only enabled for certain user groups?</li></ul><h3>Make a plan, identify the core components that are necessary</h3><p>After being aware of what you are dealing with and having a good understanding of the page’s purpose, actions, states, and features, it makes sense to start thinking about the future version of the page.</p><p>For my team, it was very useful to split up the main aspects of the page. This allowed us to asses each aspect individually and in more detail. We ended up splitting by technology, as well as splitting by components. Our goal was to have an expert for each area, who would then be able to brief the rest of the team and answer more in-depth questions.</p><h4>Logically split up what you are porting into concerns</h4><p>Look at what you are porting and try to logically separate it out into components. When you are using a design system or component library, try to identify the matching components and assess each component’s functionality individually. This will help you to not be blocked along the way realizing the component won’t fully match your needs.</p><h4>Figure out where and how to get the data</h4><p>Since we were only porting a single section of an app to an already existing project, using the existing GraphQL endpoint was the obvious choice. To get an idea of how many queries we needed and which fields to actually query, it helped to browse the <strong>GraphQL schema</strong> over and over again.</p><p>Make sure to create all necessary queries and mutations that you will later on need. This not only helps you to get an idea of what you are dealing with, but at the same time can help to identify <strong>missing queries, mutations, and fields</strong> in your API. Identifying those missing fields early in the process is important to avoid blocking backend work later in the port.</p><blockquote>Sharing is caring</blockquote><p>Personally, I really liked using <a href="https://insomnia.rest/graphql/">Insomnia</a> for assessing the current state of the API. It allows you to easily create all queries and mutations and will save you time later on when actually implementing the queries and mutations. It was also very handy that you are able to export the workspace to share it quickly with your peers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMZe-MjMONKSMqTHTas3Lg.png" /><figcaption>The master plan, listing all components and queries/mutations that are needed.</figcaption></figure><h3>Decision making and planning, aligning the team</h3><p>This is the most important step in my opinion. This is the step, where each expert gives a short summary on what they have discovered while assessing their area of interest.</p><p>Here are a few questions that came up during these discussions:</p><ul><li>Do we have a <strong>shared and/or existing component</strong> that we can reuse instead of building a new one? If yes, do we need to tweak it? How much effort will it be to make it match our needs? Should we consider building a new component for this?</li><li>Does this component depend on any other components?</li><li>Do any other components depend on this component? Is it blocking?</li><li>What are the main challenges of the component?</li><li>How do we provide the data for this component? Which GraphQL queries and/or mutations will we need for this component?</li></ul><p>After talking about the section’s components and their functionality, it makes sense to break down the tasks and determine a rough timeline. This reduces the risk of being blocked right at the beginning. It also gives backend teams the opportunity to start working on issues that were identified early to prevent friction later on. Always start with the components that might be blocking your peers on other tasks.</p><h3>🐛-hunt</h3><p>Don’t ship without doing a bug hunt before. We did our bug hunt approximately <strong>two weeks before we wanted to release</strong> the ported section. Running a successful bug hunt requires some preparation, you want to make sure you provide good instructions that contain the most important aspects for the bug hunters to get up and running quickly.</p><ul><li>Make sure they know of something that allows them to quickly identify whether they are looking at the React or Rails version of the page. You don’t want people to look for bugs on the non-React page.</li><li>If your users are unfamiliar with that specific page, give them an idea of the purpose of that page, its actions, states and features. Don’t go into too much detail though, because you want the testers to actually test and not follow your own workflows that you have established while working on that page.</li><li>Mention known changes / limitations / bugs so testers don’t create issues for those.</li><li>Provide instructions on where to log the issue, this can be a link to a github template or a link to an excel sheet. Make sure your testers leave details with the issues, e.g. steps to reproduce, the browser version, so you’ll be able to reproduce the bug they found later on.</li></ul><p>After the bug hunt, determine which issues are high priority and which are rather low priority. High priority issues are definitely issues that prevent the user from completing their usual workflows, whereas low priority issues are often related to smaller styling issues.</p><p>If nothing bigger than just a few low priority issues come up, it gives you enough time to fix those bugs in time. Otherwise, you can still be thankful your bug hunters found the bugs before releasing. Better they find it, than your users. Pushing back the release is always the better option than having to rollback in production and affecting your users in their workflows.</p><h3>What I learned</h3><ul><li>Preparation and assessing the existing code before actually starting to code is the most important piece, <strong>don’t start to code before having a plan</strong></li><li><strong>Look at performance early</strong>, you don’t want any surprises right before or after launching 🚀</li><li><strong>Instrumentation / monitoring is everything</strong>, this also applies to looping in support and monitoring support channels</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83a011da5a2a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/successfully-porting-complex-data-driven-frontends-to-react-w-graphql-83a011da5a2a">Successfully porting complex data-driven frontends to React with GraphQL</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why GraphQL Connection types don’t work well with Apollo cache]]></title>
            <link>https://medium.com/swlh/why-graphql-connection-types-dont-work-well-with-apollo-cache-c1858a897e12?source=rss-3f1172321468------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1858a897e12</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[apollo-client]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Neele Barthel]]></dc:creator>
            <pubDate>Tue, 04 Jun 2019 14:01:01 GMT</pubDate>
            <atom:updated>2020-01-13T21:13:51.789Z</atom:updated>
            <content:encoded><![CDATA[<p>Spoiler alert –this article won’t provide a perfect solution– because there really isn’t one (yet). It will outline the risks and problems you might run into trying to keep Apollo cache in sync with what is on the server when querying and mutating GraphQL Connection types.</p><p><em>To completely understand what this article is about, you should be familiar with GraphQL Connections and Apollo in general.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhku7MYgyTakrM_wO7VsAA.png" /><figcaption>The users dashboard where they can add, edit and delete posters.</figcaption></figure><p>Let’s assume we have <a href="https://blog.apollographql.com/explaining-graphql-connections-c48b7c3d6976">a GraphQL Connection</a> called posters. The connection allows us to use arguments such as first, last, before and after to query only a selection of the posters. Especially for implementing pagination this can be very helpful. However, it also comes with some caveats when trying to keep Apollo cache in sync with what is on the server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4313532ff8cd7786e3820988fca4ac6/href">https://medium.com/media/c4313532ff8cd7786e3820988fca4ac6/href</a></iframe><p>Querying this, Apollo cache will save the list of posters to the cache. The key of the object of posters will include the argument we passed to the query. In this case this would be posters({&quot;first&quot;: 50}).</p><h3>Updating an item</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4015767067f64aeee3e5142a1e469465/href">https://medium.com/media/4015767067f64aeee3e5142a1e469465/href</a></iframe><p>Since the mutation returns the updated poster object which was previously fetched by our initial posters query, Apollo cache is able to update the previously fetched object that was saved in the cache. This is because each poster has a unique ID, consisting of the poster id and the objects __typename. As a result, all references to the just updated object will be updated automatically. ✨</p><h3>Creating an item</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47bfcbb472fc3d7d83b1136bfd823020/href">https://medium.com/media/47bfcbb472fc3d7d83b1136bfd823020/href</a></iframe><p>When creating a poster, it is obvious that the poster is an addition to the existing posters. Therefore, Apollo will save the new poster object itself to the cache. However, it won’t know that we want the new poster object to now be part of the posters({&quot;first&quot;: 50})` object we queried earlier.</p><p>As a result, our list of posters that we fetched earlier, won’t be updated automatically and our cache will be out of sync compared to the data on the server. <strong>To stay in sync between the server and our local Apollo cache, we can try a few different approaches.</strong></p><h4>1. Modify the possible payload of the mutation</h4><p>Instead of only returning the recently created poster object in the mutation’s payload, we could also return all the posters we fetched earlier and update what is stored in posters({&quot;first&quot;: 50}). Our mutation could look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13a741156162cc5bc2afab677c91dfa2/href">https://medium.com/media/13a741156162cc5bc2afab677c91dfa2/href</a></iframe><p>As you might be able to tell, this comes with the caveat of having to define the exact same arguments in the mutation’s payload, that we defined in the actual query. Which in our case means that the mutation expects a whole lot of arguments that are actually not meant for the mutation but its payload instead.</p><h4>2. Update the cache manually</h4><p>Updating the cache manually seems like a great idea at first. We basically read our query from the cache, add our new element that we got in the mutations payload and finally write it back to the cache. YAY, problem solved! 🎉</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/709501f74c9991f9e6a9645ce7e9a81b/href">https://medium.com/media/709501f74c9991f9e6a9645ce7e9a81b/href</a></iframe><p>Unfortunately, it is not as easy as the code example above. Not only do we need to manually update the cursor field on each added node with a value we don’t know, we’d also have to manually update hasNextPage and hasPreviousPage according to the page size. This is because we only ever get back the poster object, but not in the context of the Connection.</p><p>Here are some examples that make it clear why local cache updates are most of the time troublesome and not sufficient when querying GraphQL Connection types.</p><h4>What if the initial query already fetched 50 posters and saved them to the cache?</h4><p>The result will still be saved to the cache, however, we’ll have 51 items stored in the cache for the posters object that we queried with the first: 50 argument.</p><h4>What if the initial query by default sorts the posters descending by name and we wanted to add a poster with the name <em>Apple</em> to our posters?</h4><p>We’ll end up with inconsistencies regarding sorting. Unless we loop over the array to figure out where it should go before appending it to the existing results.</p><h4>What if our posters actually used pagination, and our first query gave us back 49 items. We then add 2 items.</h4><p>We’ll have trouble handling pagination correctly. Each item needs its cursor. We would need to manually check if items are more than 50 and would have to change the hasNextPage field to be true. We would then need to only store the first item in the cache, so we don’t exceed our page size of 50.</p><p>Now, as soon as we try to query the –now existing– second page, we will realise that updating the cache manually isn’t going to work in all cases.<br>Since we never got the 50th poster back from the server, and we only added this item to the cache ourselves with a made up cursor, the server won’t be able to fetch our second page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9470cca6675e481af79d1049c8bdf412/href">https://medium.com/media/9470cca6675e481af79d1049c8bdf412/href</a></iframe><h4>3. Refetch the initial query</h4><p>When executing the mutation, Apollo allows you to use the prop refetchQueries on the Mutation component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f594d027e1343b58684d87a1a24831a4/href">https://medium.com/media/f594d027e1343b58684d87a1a24831a4/href</a></iframe><p>This will guarantee that, after the mutation has completed, we get the updated data from the server with the context of the updated Connection type. This means that our previously created poster comes back from the server with correct cursor and pageInfo for the Connection.</p><p>🚨 However, refetching queries comes with the cost of an additional round-trip and might cause your UI to go back into some kind of loading state until the second HTTP request is resolved.</p><h3>Deleting an item</h3><p>Deleting posters comes with similar edge cases as creating posters does, though I’m not going to dive into this deeper in this post.</p><h3>The @connection directive</h3><p>Though Apollo has a <a href="https://www.apollographql.com/docs/react/features/pagination/#the-connection-directive">solution for normalising the cache key</a>, this is not of big help for most of our use cases. Let’s look at the previously mentioned possible solutions again with having the @connection directive in mind.</p><h4>1. Modifying the possible payload of the mutation</h4><p>Since we will always need to provide a first argument for our posters query, it would not help us with not having to pass the query arguments to the mutation, if we queried for the posters payload.</p><h4>2. Updating the cache manually</h4><p>Using cache updates, we would still be stuck with not having correct cursors and having to manually set the pageInfo fields. However, using a @connection directive, we could make our query save to the cache without having a semantically incorrect key for our query results.</p><h4>3. Refetching the initial query</h4><p>Using a @connection directive when refetching the initial query, will not directly enhance this option. However, it is definitely a nice addition when dealing with a resource that will likely be paginated in multiple places with varying arguments for the query. It will make it easier for you to find specific resources in your cache, because you can disregard the arguments (if not specified differently) that are otherwise part of the Apollo cache keys.</p><h3>Conclusion</h3><ul><li>Updating Apollo cache manually can lead to problems, when used on GraphQL Connection types.</li><li>There isn’t a perfect solution for this yet, decide on a case by case basis what’s the best way for your use case to handle this. E.g. There are cases where local cache updates temporarily can make sense.</li><li>If you want to be 100% sure that you won’t end up with inconsistencies, do a refetch and accept the cost of an additional round trip.</li></ul><p>Did I miss something obvious? Let me know and I’ll be happy to update this article. 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1858a897e12" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/why-graphql-connection-types-dont-work-well-with-apollo-cache-c1858a897e12">Why GraphQL Connection types don’t work well with Apollo cache</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>