<?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 Patrick Zawadzki on Medium]]></title>
        <description><![CDATA[Stories by Patrick Zawadzki on Medium]]></description>
        <link>https://medium.com/@patzawad?source=rss-4519aa21b096------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lpS8lUUpw6EGDE6NWOiA4A.jpeg</url>
            <title>Stories by Patrick Zawadzki on Medium</title>
            <link>https://medium.com/@patzawad?source=rss-4519aa21b096------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:54:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@patzawad/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[Create an SDL Field with GraphQL Modules for Schema Stitching]]></title>
            <link>https://javascript.plainenglish.io/creating-an-sdl-field-with-graphql-modules-for-schema-stitching-38e4f8e6c482?source=rss-4519aa21b096------2</link>
            <guid isPermaLink="false">https://medium.com/p/38e4f8e6c482</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Patrick Zawadzki]]></dc:creator>
            <pubDate>Thu, 17 Mar 2022 14:28:36 GMT</pubDate>
            <atom:updated>2022-03-18T09:32:13.640Z</atom:updated>
            <content:encoded><![CDATA[<h4>A guide on creating SDL Field with GraphQL modules.</h4><p><a href="https://www.graphql-modules.com/">GraphQL modules</a> are a handy way to build modern GraphQL applications in a compartmentalized way. Created by The Guild, this handy library lets devs break apart their GraphQL schema in a way that is easier to test and develop in the long term.</p><p>Enter <a href="https://www.graphql-tools.com/docs/schema-stitching/stitch-combining-schemas">GraphQL Schema Stitching</a>, a convenient way to combine subschemas into a large “gateway” schema for applications to consume. In its simplest terms, it&#39;s like a SQL join for your GraphQL Schemas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y-v6rdyclzniSXwB.png" /><figcaption>Image from GraphQL Tools Schema Stitching Docs</figcaption></figure><p>An approach to combining schemas in schema stitching is to use an SDL with directives. Typically when trying to find more details about a GraphQL Schema, introspection is used to find out about all the available types and mutations on a schema. However, with directives, introspection doesn’t work since the directives will be omitted from the output and the gateway will be forced to create its own merge configurations to combine subschemas. Creating those merge configs can suck and directives make it a little easier.</p><p>A challenge with the SDL field is that it needs access to the entire schema for the application in order to generate the correct string and append the directives needed for schema stitching. Using the schemaBuilder option on the createApplication config we’re able to do some magic ✨ to make it work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Gk6UbUwkqnv_1LV4dQagA.png" /></figure><p>The sdlSchemaBuilder below is able to take in the resolvers, and typedefs from the combined GraphQL modules and add in the required resolvers, typedefs, and schema transformers in order for the schema directives to appear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FzFam0Tj75ngZZg48ysanQ.png" /><figcaption>sdlSchemaHelper for the schemaBuilder in a GraphQL module createApplication</figcaption></figure><pre>const { print } = require(&#39;graphql&#39;)<br>const { gql } = require(&#39;graphql-modules&#39;)<br>const { makeExecutableSchema } = require(&#39;@graphql-tools/schema&#39;)<br>const { stitchingDirectives } <br>       = require(&quot;@graphql-tools/stitching-directives&quot;)<br>const { mergeTypeDefs, <br>        mergeResolvers <br>      } = require(&#39;@graphql-tools/merge&#39;)<br>const { stitchingDirectivesTypeDefs, <br>        stitchingDirectivesValidator<br>      } = stitchingDirectives()</pre><pre>const sdlQuerySchema = gql`<br>   type Query {<br>      _sdl: String!<br>   }</pre><pre>`</pre><pre>module.exports = ({ typeDefs, resolvers }) =&gt; {<br>  const directivesTypeDefs = mergeTypeDefs([<br>     stitchingDirectivesTypeDefs,<br>     typeDefs,<br>     sdlQuerySchema <br>  ])</pre><pre>  const sdlQueryResolvers = {<br>    Query: {<br>      _sdl: () =&gt; print(directivesTypeDefs)<br>    }<br>  }</pre><pre>  const mergedResolvers = <br>    mergeResolvers([resolvers,    sdlQueryResolvers])</pre><pre>  return makeExecutableSchema({<br>    typeDefs: directivesTypeDefs,<br>    schemaTransforms: [stitchingDirectivesValidator],<br>    resolvers: mergedResolvers<br>  })</pre><pre>}</pre><p>By using the mergeResolvers mergeTypeDefs print and makeExecutableSchema functions we’re able to combine the already combined application’s schema with the additional _sdl field, _sdl resolver, and the schema directives for the application to create a Schema Stitching with Directives compatible GraphQL modules application! That’s a mouthful, but I hope this helps!</p><p>Happy Coding!</p><p>— Pat</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and</em><strong><em> </em></strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38e4f8e6c482" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/creating-an-sdl-field-with-graphql-modules-for-schema-stitching-38e4f8e6c482">Create an SDL Field with GraphQL Modules for Schema Stitching</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>
        <item>
            <title><![CDATA[Apollo Client vs Redux: Learnings and Experience]]></title>
            <link>https://javascript.plainenglish.io/apollo-client-vs-redux-learnings-and-experience-c116d139ca0f?source=rss-4519aa21b096------2</link>
            <guid isPermaLink="false">https://medium.com/p/c116d139ca0f</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[apollo-client]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Patrick Zawadzki]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 22:52:51 GMT</pubDate>
            <atom:updated>2021-03-23T17:31:46.504Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AwCK3zVtvGdiowzW.jpeg" /></figure><p>The ever changing world of front end development continues to evolve and introduce many different libraries to solve your problems. As GraphQL continues to grow in popularity, the tools and libraries surrounding it change also. Recently I helped write a new application that interacted solely with a GraphQL backend, and used Apollo Client (AC) to interact with instead of Redux in our React frontend application. Having previously written many javascript apps with Redux, here are some takeaways from my experience.</p><p><em>Disclaimer: Comparing the two libraries assumes you are working with a GraphQL backend. Apollo Client doesn’t work with other types of backends and isn’t a viable alternative to Redux in that case.</em></p><h4><strong>Built-in Lifecycle Management</strong></h4><p>AC has a lot of handy states built into its useQuery and useMutation functions that redux either needs manually, or requires a library to duplicate.</p><pre>// Apollo&#39;s built in loading/data/error responses <br>const [getData, { loading, data, error }] = useQuery(MY_QUERY)</pre><p>While Redux doesn’t have these built in, you can either build the states within your reducers and actions, or use some of the many plugins available for redux.</p><h4><strong>Strict Shape of Data</strong></h4><p>A major advantage of AC, is how closely it tracks your GraphQL store and it’s shape. This means no need to create reducers and no need to define the shape of your store. AC gives you the confidence that your store shape <em>cannot be changed</em> without updating your GraphQL types, or your <a href="https://www.apollographql.com/docs/react/caching/cache-configuration/#typepolicy-fields">type policies</a>. Redux is loose enough in its requirements where you can alter the state as you please, if you do not follow good practices.</p><p>With the typed nature of the AC store, it also provides some layers of type safety. In my case, we used a React + Javascript frontend, however type safety could also be achieved with Typescript on your frontend.</p><h4><strong>Poor Plugin Support</strong></h4><p>AC does not support plugins at this time, while redux has a quite robust plugin ecosystem. From my experience, the library did not leave many gaps that needed to be filled however. A common plugin in redux is <a href="https://github.com/reduxjs/redux-thunk">thunk</a> which provides the ability to interact with your store asynchronously. With AC’s usage of hooks and the different “response states” (loading, data, error, and even <a href="https://www.apollographql.com/docs/react/performance/optimistic-ui/#gatsby-focus-wrapper">optimistic UI</a>), many of the common requirements for a modern frontend application are handled.</p><h4><strong>Maturity</strong></h4><p>AC is new, the project hasn’t been around for a long time, and it is closely coupled to another new technology (GraphQL). Considering these two restrictions, the overall potential developer base is smaller as a result. This means that documentation isn’t as prevalent, the community is still growing, and most importantly, library itself is still undergoing changes. Redux is older, works with a wider variety of backends, and has a strong community around it because of it. For someone starting out in frontend development, choosing Redux may be the better path simply for the amount of support available.</p><p>AC has a larger barrier to entry, since it is not as trivial to get spun up. You can’t simply take any frontend and hook it up to any backend, redux provides you that freedom since it is not as opinionated as AC.</p><h4><strong>Summary</strong></h4><p>Redux likely isn’t going anywhere anytime soon. It is a widely known and commonly used framework across a multitude of frontend frameworks. This gives it a massive advantage, however, it does require some more setup and management to work well. AC solves a lot of common front end problems, but tightly couples you to a GraphQL backend. Next time you have an application you are going to write, if you’re fortunate to only need a GraphQL backend to interact with, AC is worth a try.</p><p>Thanks for reading!<br>Pat</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c116d139ca0f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/apollo-client-vs-redux-learnings-and-experience-c116d139ca0f">Apollo Client vs Redux: Learnings and Experience</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>
        <item>
            <title><![CDATA[Apollo Client Data Normalization and Storage]]></title>
            <link>https://javascript.plainenglish.io/apollo-client-data-normalization-and-storage-e03c75dd52b9?source=rss-4519aa21b096------2</link>
            <guid isPermaLink="false">https://medium.com/p/e03c75dd52b9</guid>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo-client]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Patrick Zawadzki]]></dc:creator>
            <pubDate>Sat, 09 Jan 2021 19:13:30 GMT</pubDate>
            <atom:updated>2021-03-24T13:17:27.708Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UPbAEJPLOQLCdXAD" /></figure><p>Apollo client is a powerful frontend GraphQL library that allows an application using GraphQL to query itself, and the connected GraphQL data service. It is a client side state management library that integrates deeply with GraphQL backends.</p><p>Under the covers, Apollo client takes your GraphQL query response, and flattens it into a key-value storage system. Take the following example:</p><pre>// GraphQL Query and Type<br>type Account { <br>  id: ID!<br>  userName: String!</pre><pre>}</pre><pre>query getAccount() {<br>  account {<br>    id<br>    userName<br>    __typename // not required, but for illustration<br>  }  <br>}</pre><p>The query above for a value on type Account, would return a response like this:</p><pre>{<br>  data: {<br>    account: {<br>      id: 1,<br>      userName: &#39;user&#39;,<br>      __typename: &#39;Account&#39;<br>    }<br>  }<br>}</pre><p>Apollo client by default, would store this on the client side in a key-value manner below:</p><pre>{<br>  &#39;Account:1&#39;: { // this key is stored by Apollo client<br>      id: 1,<br>      userName: &#39;user&#39;,<br>      __typename: &#39;Account&#39;<br>    }<br>}</pre><p>Apollo takes the <strong>__typename</strong> and the <strong>id</strong> fields from the response and <a href="https://www.apollographql.com/docs/react/caching/cache-configuration/#generating-unique-identifiers">combines them into the key,</a> then stores the associated value with it.</p><p><strong>The Problem</strong></p><p>Apollo client doesn’t know your data, and it doesn’t know the relationship between your types. For more complex scenarios, Apollo may incorrectly store the data you’re querying for, and cause your application to show duplicate values. Your GraphQL server will return the data as you expect, but the Apollo client normalizes data — causing clashes. To solve this issue you need to use <a href="https://www.apollographql.com/docs/react/caching/cache-configuration/#disabling-normalization">key fields</a> on your TypePolicy for the affected types.</p><p><strong>Example</strong></p><p>Let’s say we run an app that keeps track of owner equity in different companies.</p><pre>type User {<br>  id: ID!<br>  name: String!  <br>  email: String!<br>}<br>type Company {<br>  id: ID!<br>  name: String!<br>  country: String!<br>  owners: [Owner]!<br>}</pre><pre>type Owner implements User {<br>  equity: Float!<br>  company: Company!<br>}</pre><pre>--- Example Query ---<br>query getCompanies() {<br>  companies {<br>    id<br>    name<br>    owners {<br>     id<br>     name<br>     equity <br>    }<br>  }<br>}</pre><p>Equity is based <em>per company </em>and nothing is preventing a user from owning a piece of <em>multiple companies</em>. Therefore, when we pull the data from the backend, there is a chance of clashing because the <em>Owner</em> type uses the same id as the <em>User </em>type, and Apollo Client will end up generating duplicate keys in its flattened data store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*gB5SirOsnUHDEcMj" /></figure><p>Let’s take Elon Musk, he has equity in SpaceX and Tesla. Our data response for the example query above, would look like this:</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;companies&quot;: [<br>      {<br>        &quot;id&quot;: 1,<br>        &quot;name&quot;: &quot;SpaceX&quot;,<br>        &quot;owners&quot;: [<br>          {<br>            &quot;id&quot;: 1,<br>            &quot;name&quot;: &quot;Elon Musk&quot;,<br>            &quot;equity&quot;: 0.95<br>          }<br>        ]<br>      },<br>      {<br>        &quot;id&quot;: 2,<br>        &quot;name&quot;: &quot;Tesla&quot;,<br>        &quot;owners&quot;: [<br>          {<br>            &quot;id&quot;: 1,<br>            &quot;name&quot;: &quot;Elon Musk&quot;,<br>            &quot;equity&quot;: 0.93<br>          }<br>        ]<br>      }<br>    ]<br>  }<br>}</pre><p>When Apollo client would receive this data, it would attempt to save Musk’s ownership under Owner:1 and create a clash.</p><pre>{<br>  &quot;Owner:1&quot;: {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Elon Musk&quot;,<br>    &quot;equity&quot;: 0.95<br>  }<br>}</pre><pre>---- Clashes With ----<br>{<br>  &quot;Owner:1&quot;: {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Elon Musk&quot;,<br>    &quot;equity&quot;: 0.93<br>  }<br>}</pre><p>Implementing a key field definition for the <strong>Owner</strong> type in our client side type policies will fix this</p><pre>const Owner = {<br>  keyFields: [&#39;id&#39;, &#39;equity&#39;, &#39;name&#39;] // Apollo Client will generate a new identifier, based on the fields you pass in.<br>}</pre><pre>const typePolicies = {<br>  Owner<br>}<br>export default typePolicies</pre><p><a href="https://www.apollographql.com/docs/react/caching/cache-configuration/#disabling-normalization">Key fields can be many different things</a>, you can set it to false and Apollo will take the entire value, stringify it, and use it as the key. You can also use an array of fields, like above, or a KeyFieldsFunction to generate your own. Now our flattened data structure, will contain both Owner data sets.</p><pre>{<br>  &quot;Owner:1|equity:0.95|name:&#39;Elon Musk&#39;&quot;: {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Elon Musk&quot;,<br>    &quot;equity&quot;: 0.95<br>  },<br>  &quot;Owner:1|equity:0.93|name:&#39;Elon Musk&#39;&quot;: {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Elon Musk&quot;,<br>    &quot;equity&quot;: 0.93<br>  }<br>}</pre><h4>Conclusion</h4><p>Thanks for reading! I hope this helps fix someone’s problem when implementing Apollo Client for their frontend app. If there is an issue with the article, please reach out so I can fix it!</p><p>— Pat<br><a href="https://twitter.com/PatZawa">@patzawa</a><br><a href="http://www.patz.dev/">patz.dev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e03c75dd52b9" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/apollo-client-data-normalization-and-storage-e03c75dd52b9">Apollo Client Data Normalization and Storage</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>