<?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 Alex Shtykov on Medium]]></title>
        <description><![CDATA[Stories by Alex Shtykov on Medium]]></description>
        <link>https://medium.com/@shtbik?source=rss-23419506c6b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sZwFj1sYei_9Bg9vV0pDvA.jpeg</url>
            <title>Stories by Alex Shtykov on Medium</title>
            <link>https://medium.com/@shtbik?source=rss-23419506c6b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:21:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shtbik/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[Apollo Mocking Techniques]]></title>
            <link>https://javascript.plainenglish.io/apollo-mocking-techniques-e24e78cf6acb?source=rss-23419506c6b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e24e78cf6acb</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo-client]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Alex Shtykov]]></dc:creator>
            <pubDate>Fri, 13 Mar 2026 01:25:37 GMT</pubDate>
            <atom:updated>2026-03-16T01:03:43.947Z</atom:updated>
            <content:encoded><![CDATA[<h4>Unleash Frontend Power — No API? No Problem</h4><h3>🎯 The Principle</h3><blockquote>Frontend development should NOT be blocked by the API</blockquote><p>Teams often hit the same bottleneck:</p><ul><li>UI is ready</li><li>feature development has started</li><li>but API endpoints <strong>aren’t</strong> <strong>there yet</strong></li></ul><p>Some teams simply wait, shifting their focus to another project.<br>But if you’re using Apollo Client to interact with your API, you don’t have to.</p><p>Apollo allows you to resolve fields locally, intercept GraphQL operations, and simulate responses on the client. This means frontend engineers can <strong>continue building features even when the backend is incomplete</strong>.</p><p>Over time, at <a href="https://leonardo.ai/">Leonardo.AI</a> we developed a practical strategy for this.</p><p>Not hacks. Not temporary workarounds.<br>A <strong>clear framework for mocking GraphQL APIs in production codebases.</strong></p><h3>⚡ The Mocking Decision Framework</h3><p>Not every situation needs the same solution.<br>Choose the <strong>lightest technique that unblocks development</strong>.</p><figure><img alt="The Mocking Decision Framework" src="https://cdn-images-1.medium.com/max/1024/1*sMlEk-NxmeRSqzdHOLLd_Q.png" /><figcaption>This keeps mocks <strong>simple, intentional, and temporary</strong></figcaption></figure><h3>1️⃣ Quick Testing — Request Interception</h3><p>Sometimes you just need to test a UI change:</p><ul><li>small data tweak</li><li>reproducing an edge case</li><li>validating how the UI behaves with slightly different API responses</li></ul><p>Browser request interceptors such as <a href="https://requestly.com/">Requestly</a> or <a href="https://tweak-extension.com/">Tweak</a> let you override API responses instantly.</p><figure><img alt="Requestly — GraphQL support​" src="https://cdn-images-1.medium.com/max/1024/1*UPvdPXE56B2DGqx6hm85zQ.gif" /><figcaption>Example of how Requestly solves this with <a href="https://requestly.com/products/http-interceptor/modify-and-mock-apis/">operation name filters</a></figcaption></figure><p><em>Pros</em></p><ul><li>zero code changes</li><li>extremely fast</li></ul><p><em>Cons</em></p><ul><li>not type-safe</li><li>not easily shareable</li><li>not suitable for tests</li></ul><p>Think of this as <strong>personal experimentation</strong>, not a long-term solution.</p><h3>2️⃣ Extending Existing Queries — Local-Only Fields</h3><p>A common scenario:</p><p>You need a new field in the UI, but the API doesn’t expose it yet. Apollo Client supports <strong>local-only fields</strong> via the <a href="https://www.apollographql.com/docs/react/local-state/managing-state-with-field-policies#using-local-only-fields-as-graphql-variables">@client</a> directive.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed3d9e2baf9a7e4d5a436dd4620263d7/href">https://medium.com/media/ed3d9e2baf9a7e4d5a436dd4620263d7/href</a></iframe><p>When Apollo sees <a href="https://www.apollographql.com/docs/react/local-state/managing-state-with-field-policies#using-local-only-fields-as-graphql-variables">@client</a>:</p><ul><li>the field is <strong>removed from the network request</strong></li><li>the value is resolved locally</li><li>the final response merges server and client data</li></ul><p>You then define how that field behaves using <strong>cache </strong><a href="https://www.apollographql.com/docs/react/caching/cache-field-behavior"><strong>type policies</strong></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1cfed3eb1f601b29c7b8f30b91bfebd8/href">https://medium.com/media/1cfed3eb1f601b29c7b8f30b91bfebd8/href</a></iframe><p>The final step is to extend the schema so Codegen knows the type of the likes field, since it doesn&#39;t exist in the server schema yet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccd8af2b7bd9390c90641de8a2f4baec/href">https://medium.com/media/ccd8af2b7bd9390c90641de8a2f4baec/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abb82ddf3d60909b16eec64289b1ea78/href">https://medium.com/media/abb82ddf3d60909b16eec64289b1ea78/href</a></iframe><p>This approach is ideal when:</p><ul><li>extending existing queries</li><li>collaborating with the team</li><li>maintaining TypeScript compatibility</li></ul><p>When the API becomes available, simply:</p><ul><li>remove <a href="https://www.apollographql.com/docs/react/local-state/managing-state-with-field-policies#using-local-only-fields-as-graphql-variables">@client</a></li><li>regenerate types</li></ul><p>Done.</p><blockquote>The complete setup for this approach is available in this <a href="https://gist.github.com/shtbik/59a6af0d0397b866285eeedf6d32a16f">Gist</a>, including the schema definitions, Codegen configuration, and custom cache behaviour for the <a href="https://www.apollographql.com/docs/react/local-state/managing-state-with-field-policies#using-local-only-fields-as-graphql-variables">@client</a> field.</blockquote><h3>3️⃣ Building New Features — MockLink</h3><p>Sometimes the problem isn’t a missing field.<br>The <strong>entire operation doesn’t exist</strong>.</p><p>Instead of waiting, discuss the query/mutation design with your API team, define the schema locally, and mock the request.</p><p>Let’s create and use a new likePreset mutation that doesn&#39;t yet exist on the server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2243331c69c868266133b0ab81c93ae5/href">https://medium.com/media/2243331c69c868266133b0ab81c93ae5/href</a></iframe><p>Apollo Client provides tooling that lets you intercept operations and return predefined responses without sending a network request — exactly like mocking Apollo in unit tests, but this time inside your application.</p><p>Below is a simplified example of how to set up a custom Apollo link and the request mock — the full version is available <a href="https://gist.github.com/shtbik/58dcd664ec0cb258323ff0b318bc7356#file-mocked-apollo-provider-ts-L32">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a20a7b829c4fb14aca4b98850e58956/href">https://medium.com/media/4a20a7b829c4fb14aca4b98850e58956/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f2441a5bf55b85d3317540fadb02d63/href">https://medium.com/media/4f2441a5bf55b85d3317540fadb02d63/href</a></iframe><p>This approach can coexist with real API operations. The same component can execute both mocked and existing GraphQL requests. A custom Apollo link inspects the operation name and decides whether to return a mocked response or forward the request to the real API.</p><p>If needed, an application can also use multiple/nested ApolloProvider instances, each configured with its own set of mocks.</p><p>This unlocks:</p><ul><li>full feature development</li><li>multi-engineer collaboration</li><li>realistic UI workflows</li><li>test coverage</li></ul><p>Use this approach when the <strong>API is at least two weeks away</strong>, as it requires some maintenance and cleanup afterward.</p><blockquote>The complete setup for this approach is available in this <a href="https://gist.github.com/shtbik/58dcd664ec0cb258323ff0b318bc7356">Gist</a>, including the schema definitions, Codegen configuration, the ApolloProvider setup with MockLink, and an example of calling a mocked query.</blockquote><h3>4️⃣ Advanced Case — Extending Existing Queries</h3><p>The case looks like this:</p><ul><li>the query exists</li><li>but the feature needs <strong>new filtering or arguments</strong></li></ul><p>Example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a58f0746213fea199993f2fa3aedb80/href">https://medium.com/media/1a58f0746213fea199993f2fa3aedb80/href</a></iframe><p>If the backend doesn’t support userId, the request fails. The <a href="https://www.apollographql.com/docs/react/local-state/managing-state-with-field-policies#using-local-only-fields-as-graphql-variables">@client</a> directive can’t be used here because it works only for fields, not arguments.</p><p>This hybrid approach builds on the <strong>3. Building New Features — MockLink </strong>described earlier, but applies it selectively to existing requests.</p><ol><li>extend the schema locally</li><li>intercept requests with <strong>certain variables </strong>(e.g. userId)</li><li>mock the response only when there is a match</li></ol><p>Example logic:</p><pre>export const getUserPresetsMock = {<br>  request: {<br>    query: GetPresetsDocument,<br>  },<br>  // mock only when the new argument is present<br>  variableMatcher: (variables) =&gt; !!variables?.userId,<br>  result: { ... }<br>}</pre><p>Behavior:</p><ul><li>getPresets() → real API request</li><li>getPresets({ userId }) → mocked response</li></ul><p>This lets you <strong>extend existing APIs without breaking other consumers</strong>.</p><blockquote>The setup for this approach is available in this <a href="https://gist.github.com/shtbik/dd3e97056d9a97f09df79e070497ed98">Gist</a>. It builds on the previous <a href="https://gist.github.com/shtbik/58dcd664ec0cb258323ff0b318bc7356">MockLink</a> example and includes a mock with variableMatcher.</blockquote><h3>🧠 The Real Benefit</h3><ul><li>These techniques are not just about mocking</li><li>They enable a different development workflow</li><li>The frontend stops being blocked — and starts <strong>driving integration</strong></li></ul><h3>🚀 Final Takeaway</h3><p>Always pick the <strong>simplest mock technique that unblocks progress</strong>.</p><ul><li>small tweak → intercept request</li><li>new field → <a href="https://www.apollographql.com/docs/react/local-state/managing-state-with-field-policies#using-local-only-fields-as-graphql-variables">@client</a></li><li>new operation → MockLink</li><li>extended query → conditional mocking with <em>variableMatcher</em></li></ul><h3>🙌 Want a Reusable Version of This?</h3><p>If this framework looks useful for your team, let us know.<br>We’re considering publishing the reusable parts of this setup as:</p><ul><li>a <strong>small package</strong> to simplify conditional mocking in ApolloProvider</li><li>an <strong>AI Agent Skill</strong> that helps engineers choose the right mocking technique and guides them through the initial setup</li></ul><p>The goal would be simple: make it easier to pick the right approach, bootstrap the boilerplate, and start building without waiting on the API.</p><p>If that would help you, <strong>raise your hand</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e24e78cf6acb" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/apollo-mocking-techniques-e24e78cf6acb">Apollo Mocking Techniques</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>