<?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 David Mráz on Medium]]></title>
        <description><![CDATA[Stories by David Mráz on Medium]]></description>
        <link>https://medium.com/@david.mraz?source=rss-452d0ada7367------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LXgdcO9KsVNEbEf4OsxsWg.jpeg</url>
            <title>Stories by David Mráz on Medium</title>
            <link>https://medium.com/@david.mraz?source=rss-452d0ada7367------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 01:10:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@david.mraz/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[Text classification with transformers in Tensorflow 2: BERT]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/atheros/text-classification-with-transformers-in-tensorflow-2-bert-2f4f16eff5ad?source=rss-452d0ada7367------2"><img src="https://cdn-images-1.medium.com/max/1350/1*ELXoAJW5X4m9VPTIiG-1og.jpeg" width="1350"></a></p><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://medium.com/atheros/text-classification-with-transformers-in-tensorflow-2-bert-2f4f16eff5ad?source=rss-452d0ada7367------2">Continue reading on Atheros »</a></p></div>]]></description>
            <link>https://medium.com/atheros/text-classification-with-transformers-in-tensorflow-2-bert-2f4f16eff5ad?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f4f16eff5ad</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Tue, 05 May 2020 19:30:42 GMT</pubDate>
            <atom:updated>2020-05-05T19:34:45.654Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Top AI and Machine Learning Books for Business Leaders In 2020]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/atheros/top-ai-and-machine-learning-books-for-business-leaders-in-2020-6b0842f926fd?source=rss-452d0ada7367------2"><img src="https://cdn-images-1.medium.com/max/2600/1*ZWtPSHijIvyCk2m7_JBgow.jpeg" width="3500"></a></p><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://medium.com/atheros/top-ai-and-machine-learning-books-for-business-leaders-in-2020-6b0842f926fd?source=rss-452d0ada7367------2">Continue reading on Atheros »</a></p></div>]]></description>
            <link>https://medium.com/atheros/top-ai-and-machine-learning-books-for-business-leaders-in-2020-6b0842f926fd?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b0842f926fd</guid>
            <category><![CDATA[books]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[business]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Mon, 13 Jan 2020 16:01:02 GMT</pubDate>
            <atom:updated>2020-05-02T15:17:05.884Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Build GraphQL APIs for Text Analytics in Python]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://medium.com/atheros/how-to-build-graphql-apis-for-text-analytics-in-python-8f18577623cf?source=rss-452d0ada7367------2">Continue reading on Atheros »</a></p></div>]]></description>
            <link>https://medium.com/atheros/how-to-build-graphql-apis-for-text-analytics-in-python-8f18577623cf?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f18577623cf</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Wed, 08 Jan 2020 22:04:51 GMT</pubDate>
            <atom:updated>2025-03-02T18:57:49.879Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[GraphQL interfaces and unions — how to design GraphQL schema]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/atheros/graphql-interfaces-and-unions-how-to-design-graphql-schema-47066c7f30be?source=rss-452d0ada7367------2"><img src="https://cdn-images-1.medium.com/max/1045/0*tIPFtFg54FVB49ZL.png" width="1045"></a></p><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://medium.com/atheros/graphql-interfaces-and-unions-how-to-design-graphql-schema-47066c7f30be?source=rss-452d0ada7367------2">Continue reading on Atheros »</a></p></div>]]></description>
            <link>https://medium.com/atheros/graphql-interfaces-and-unions-how-to-design-graphql-schema-47066c7f30be?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/47066c7f30be</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Wed, 03 Jul 2019 08:38:31 GMT</pubDate>
            <atom:updated>2025-03-02T18:58:34.702Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[React Hooks in Apollo client for GraphQL queries and mutations]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-snippet">If you are not Medium membership subscriber, just take a look at the article for free.</p><p class="medium-feed-link"><a href="https://medium.com/atheros/react-hooks-in-apollo-client-for-graphql-queries-and-mutations-162d297677b5?source=rss-452d0ada7367------2">Continue reading on Atheros »</a></p></div>]]></description>
            <link>https://medium.com/atheros/react-hooks-in-apollo-client-for-graphql-queries-and-mutations-162d297677b5?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/162d297677b5</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Tue, 21 May 2019 10:34:57 GMT</pubDate>
            <atom:updated>2025-03-02T18:58:59.457Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Generate Javascript static types from GraphQL: TypeScript and Flow]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/atheros/generate-javascript-static-types-from-graphql-typescript-and-flow-4d28b46b8d13?source=rss-452d0ada7367------2"><img src="https://cdn-images-1.medium.com/max/2147/1*aG5kklSqY1f_iZCoe0lasg.png" width="2147"></a></p><p class="medium-feed-snippet">Javascript is usually considered as a untyped or weakly-typed language. I will not go into the discussion about this topic in this article&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/atheros/generate-javascript-static-types-from-graphql-typescript-and-flow-4d28b46b8d13?source=rss-452d0ada7367------2">Continue reading on Atheros »</a></p></div>]]></description>
            <link>https://medium.com/atheros/generate-javascript-static-types-from-graphql-typescript-and-flow-4d28b46b8d13?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d28b46b8d13</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 12:34:11 GMT</pubDate>
            <atom:updated>2025-03-02T18:59:25.889Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[GraphQL best practices for GraphQL schema design]]></title>
            <link>https://medium.com/atheros/graphql-best-practices-for-graphql-schema-design-91fcab4dec0a?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/91fcab4dec0a</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[sofware-development]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Wed, 31 Oct 2018 09:18:59 GMT</pubDate>
            <atom:updated>2019-11-26T04:40:55.921Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VhMx4OLbcLnTkojjnCVrg.jpeg" /></figure><p>This article is a part of <a href="https://graphqlmastery.com/course/graphql-language">free GraphQL Language course</a>. To fully understand the content you need to be familiar with basic GraphQL concepts like SDL language, GraphQL document syntax or <a href="http://localhost:3000/blog/input-object-type-as-an-argument-for-graphql-mutations-and-queries">GraphQL object types</a> and <a href="http://localhost:3000/blog/graphql-scalars-and-their-input-and-result-coercion">scalars</a>. If you do not have this knowledge, you can take a look at our older articles on <a href="http://localhost:3000/blog">atheros.ai</a> and on our <a href="https://medium.com/atheros">medium publication</a>.</p><h3>Introduction</h3><p>In this article, we will go through various ways and basic patterns to help design schema in the best possible way. This is definitely not a complete guide; this is just a shortlist of best practices and instructions on how to avoid the biggest pitfalls that regularly come up. For more advanced info on designing your GraphQL schemas check out our free <a href="https://graphqlmastery.com/course/graphql-language">GraphQL language course</a>. It is useful to approach schema design by making a check-list of what your schema should provide to guide you through the design process.</p><h3>Using input object type for mutations</h3><p>It is extremely important to use just one variable for your mutations and use the input object type to simplify the structure of your GraphQL documents. In our schema the example is our <strong>createPlanet</strong> mutation. In SDL this is written as follows:</p><pre>type Planet implements Node {</pre><pre><em>  id</em>: ID!</pre><pre><em>  createdAt</em>: DateTime!</pre><pre><em>  updatedAt</em>: DateTime</pre><pre><em>  name</em>: String</pre><pre><em>  description</em>: String</pre><pre><em>  planetType</em>: PlanetTypeEnum</pre><pre>}</pre><pre>input CreatePlanetInput {</pre><pre><em>  name</em>: String!</pre><pre><em>  galaxyId</em>: ID!</pre><pre><em>  description</em>: String</pre><pre>}</pre><pre>type Mutation {</pre><pre><em>  createPlanet</em>(<em>input</em>: CreatePlanetInput!): Planet!</pre><pre>}</pre><p>We can see that we only have one argument input — this is typed as an input object type. We are applying a non-null modifier to ensure that the input payload cannot be null. To get more details on this pattern including why we should use it and how to implement it, you can follow <a href="https://medium.com/atheros/json-as-an-argument-for-graphql-mutations-and-queries-3cd06d252a04">this article on input object types</a> and this one on <a href="http://localhost:3000/blog/graphql-list-how-to-use-arrays-in-graphql-schema">GraphQL lists and Non-Null modifiers</a>.</p><h3>Returning affected objects as a result of mutations</h3><p>When working with mutations it is considered good design to return mutated records as a result of the mutation. This allows us to update the state on the frontend accordingly and keep things consistent. To illustrate the concept let’s look at the following mutation:</p><pre>type Mutation {</pre><pre><em>  createPlanet</em>(<em>input</em>: CreatePlanetInput!): Planet!</pre><pre><em>  updatePlanet</em>(<em>input</em>: UpdatePlanetInput!): Planet!</pre><pre>}</pre><p>We can see that we return <strong>Planet!</strong> as a result of this mutation. This is then used by the cache and we can use it to update the store. In the <strong>createPlanet</strong> mutation, we append the object to the list of planets. This normally needs to be done in the code. In the second example for <strong>updatePlanet</strong>, however, we can update the <strong>Planet</strong> automatically by its id.</p><h3>Using paginated lists by default</h3><p>Paginated results are really important for security reasons and for the ability to limit the amount of records we would like to retrieve from the server. It is a good practice to structure paginated results as follows:</p><pre>type PageInfo {</pre><pre><em>  endCursor</em>: String</pre><pre><em>  hasNextPage</em>: Boolean!</pre><pre><em>  hasPreviousPage</em>: Boolean!</pre><pre><em>  startCursor</em>: String</pre><pre>}</pre><pre>type ConstellationConnection {</pre><pre><em>  nodes</em>: [Constellation]</pre><pre><em>  pageInfo</em>: PageInfo!</pre><pre><em>  totalCount</em>: Int!</pre><pre>}</pre><p>This pagination is based on the so-called <strong>cursor-based pagination</strong>. Whenever you fetch lists, I suggest you use paginated lists by default. You will avoid breaking changes in the schema in the future and it is almost always a much more scalable solution. You can also easily implement <strong>amount limiting</strong> and protect yourself against resource exhaustion attacks, where someone can query an overwhelming number of records from your database at once.</p><h3>Nesting your objects in queries</h3><p>When building GraphQL schemas I often see faulty patterns which affect caching and hinder the efficiency of GraphQL queries on the client. If we rewrite our planet type with this bad practice we would write something like this:</p><pre>type Planet implements Node {</pre><pre><em>  id</em>: ID!</pre><pre><em>  createdAt</em>: DateTime!</pre><pre><em>  updatedAt</em>: DateTime</pre><pre><em>  name</em>: String</pre><pre><em>  description</em>: String</pre><pre><em>  planetType</em>: PlanetTypeEnum</pre><pre><em>  galaxyId</em>: ID!</pre><pre>}</pre><p>The problem here is the <strong>galaxyId</strong>. For the cache on the frontend, there will be inconsistencies. You need to think about the schema, reuse the types, and substitute these ids with the proper type. If you want to query for the <strong>planet’s</strong> constellation you need to do two queries. First, call the planet with the <strong>galaxyId</strong>, and then pass the <strong>galaxyId</strong> to an additional query. This is really inconvenient and does not maximize the power of GraphQL. In GraphQL it is much better to nest the output types. This way we can call everything with one single request and also perform caching and batching with <a href="https://github.com/facebook/dataloader">data loader</a>.</p><pre>type Planet implements Node {</pre><pre><em>  id</em>: ID!</pre><pre><em>  createdAt</em>: DateTime!</pre><pre><em>  updatedAt</em>: DateTime</pre><pre><em>  name</em>: String</pre><pre><em>  description</em>: String</pre><pre><em>  planetType</em>: PlanetTypeEnum</pre><pre><em>  galaxy</em>: Galaxy!</pre><pre>}</pre><p>When we query for the <strong>planet</strong> and we want to include its <strong>constellation</strong> we can just call this GraphQL query:</p><pre>query getPlanets {</pre><pre>  planets {</pre><pre>    nodes {</pre><pre>      id</pre><pre>      name</pre><pre>      constellation {</pre><pre>        id</pre><pre>        name</pre><pre>        createdAt</pre><pre>      }</pre><pre>    }</pre><pre>  }</pre><pre>}</pre><h3>Elevating schema design with interfaces</h3><p>The interfaces and unions are powerful tools for abstracting different concepts, reducing complexity and simplifying our schema. The best example of interfaces is the <strong>Node Interface</strong>. The Node interface is enforced by <a href="https://relay.dev/">Relay.js</a>, but I would recommend implementing it to other schemas as well. Even if they do not use Relay.js on the frontend, it will still help to reduce complexity. To gain a more in-depth understanding of interfaces you can check out <a href="http://localhost:3000/blog/graphql-interfaces-and-unions-how-to-design-graphql-schema">this article</a> or our <a href="https://graphqlmastery.com/course/graphql-language">GraphQL language course</a>.</p><h3>Think about future schema changes</h3><p>When implementing your initial schema, try to think about all possible future changes. In general, just invest in the schema. Think about where you can expect to add additional fields in the future and add output object types and input object types there so that you will not have to introduce breaking changes later on. If you are building a more complex app, just do not use GraphQL schema generators blindly. GraphQL schema generators are definitely useful in certain cases like prototyping or for instant high-performance APIs from the database, but in general, I would suggest to think about the schema design and tailor it to your frontend needs.</p><h3>Use consistent naming in your schema</h3><p>It’s really important to keep naming conventions consistent not just in GraphQL schema design. It is common good practice to use <strong>camelCase</strong> for your fields and <strong>pascalCase</strong> for the names of types. I find also useful to name for example input types like this:</p><pre>(action)(type)Input</pre><p><strong>(action)</strong> is <strong>Create</strong>, <strong>Update</strong> or <strong>Delete</strong> and <strong>(type)</strong> is the name of the type or entity, which is being updated. We also need to ensure that some common patterns like pagination are named in the same manner. We use the <strong>PageInfo</strong> type and connection for the paginated list with nodes. Another good practice for enums is to use all capital letters for ENUM values, as they are basically constants.</p><blockquote>I hope that you liked this short list of best practices for GraphQL schema design. Feel free to ask any question and feedback on this article or GraphQL Mastery in general to <a href="/service/mailto:david@atheros.ai">david@atheros.ai</a>.</blockquote><p><em>Originally published at </em><a href="https://atheros.ai/blog/graphql-best-practices-for-graphql-schema-design">https://atheros.ai/blog/graphql-best-practices-for-graphql-schema-design</a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91fcab4dec0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/atheros/graphql-best-practices-for-graphql-schema-design-91fcab4dec0a">GraphQL best practices for GraphQL schema design</a> was originally published in <a href="https://medium.com/atheros">Atheros</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to learn GraphQL, React and Node.js faster]]></title>
            <link>https://medium.com/atheros/how-to-learn-graphql-react-and-node-js-faster-bdc95e8510c7?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdc95e8510c7</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Tue, 16 Oct 2018 10:11:01 GMT</pubDate>
            <atom:updated>2018-10-16T10:11:01.648Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8ChSQA8hpNGz9YiB_r_5g.jpeg" /></figure><p>Learning GraphQL, React, Node.js, and engineering in general is not easy for most people. In this article we will go through some of the top cognitive biases that you need to be aware of to accelerate your learning rate, to decide when to switch technologies, and to refactor your code or avoid mistakes that could lead to technical debt and inefficiently spent time. You will avoid going in circles and find that you learn each lesson more quickly.</p><h3>Introduction</h3><p>Learning programming and engineering, especially JavaScript, can be tricky. The Node.js ecosystem is changing at a fast pace, leaving your current knowledge outdated. In this fast-paced environment you need to be aware of how you can accelerate your learning and cut out unnecessary time. As the technology progresses, the important thing is not only to have some specific knowledge about the technology, but to adapt thinking patterns to the frequent changes. Thinking patterns and architecture patterns will stay similar and can be applied to different environments and languages. In this article, we will go through the top cognitive biases that are affecting our decisions when we need to refactor or change our tech stack. We will discuss how to avoid bad decisions that keep us from learning faster, and suggest tips that will help you increase your learning rate. A lot of these things are also applicable to different domains.</p><h3>Resistance to changes</h3><p>I see myself and others to be really attached to their code. A lot of people are working hard on preparing certain architecture, code base or solutions to the problem to only find that the architecture is not modular enough, too error-prone or just does not scale very well. Completely changing or refactoring the architecture is often quite time-consuming and means that a lot of your code will be removed. This is the point where most people will get resistant to change and start rationalizing and finding ways to justify their solution even though logical reasoning wouldn’t support the old solution. In this problem we are dealing with a number of cognitive biases that affect our decisions. The main biases are:</p><ul><li><strong>Commitment bias</strong></li><li><strong>Confirmation bias</strong></li><li><strong>Post-purchase rationalization</strong></li></ul><p>I see that people start new projects with an already predefined technology stack in their head. Their technology stack will match a lot with their current skills. While this is natural, it can lead to accumulating technical debt and to using technology which is not the best fit for the current modern stack. In addition, badly designed architecture leads to dissatisfaction in your team, frustration, and inefficiency. The GraphQL ecosystem is really fast-paced and is still changing a lot. Before each project you need to reevaluate and adjust your tech stack to reflect the best and most current solutions. This is much harder for projects already in progress. You invest much more time and it becomes more difficult to transition to a more suitable technology. People still tend to go with the old architecture, however, even though in the long term it means that you will choose less modern and efficient solutions and you will spend more time writing state updates, etc. A lot of people resist switching to new technologies even if that new technology would solve many problems in their application as well as saving development time. This is understandable if your codebase is too big to switch, but you should think about gradually refactoring your stack to be up to date with current modern engineering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2RfR8j5WGBfL4yiLcu7_w.jpeg" /></figure><p>Without a doubt you should not adapt new technologies blindly; you need to evaluate each technology separately. Instead of focusing on the time invested in the old code, I would recommend learning from your experience implementing the technology, and recognizing the advantages of adapting different thinking patterns. With these lessons you will learn how to quickly and efficiently adopt new technologies in the future.</p><p>We need to be especially aware about commitment bias as it can lead to the so-called <strong>Escalation of commitment</strong>. <strong>Escalation of commitment</strong> is human behaviour pattern where the individual or gourp will continue the same behaviour rather than alter course, even that decisions are clearly wrong. In certain cases, it can lead to disasters in peoples live as they are proceeding in the same bad decisions and completely ignore the negative signals. They attached a lot of ego and work to it and the willpower needed to change the decision is is increasing with the time. Once you are aware of <strong>commitment bias</strong> and other similar biases you will make better decisions when it comes to choosing your tech stack. Yand also that you will also be able to better estimate the right time for significant refactoring and changes to your app. We also need to take into account a number of other biases. The decision to migrate a technology stack is affected by the <strong>post-purchase rationalization</strong>. This means we place much higher value on past choices and try to justify these.</p><p><strong>Confirmation bias</strong> affects these decisions as well. This bias results in people tending to believe things that confirm their beliefs. This can be really dangerous if your beliefs lead to bad decision-making. You will then focus solely on facts that reinforce your beliefs. Let’s take the example of staying with technology that is gradually becoming outdated. You know that you need to switch to new technology or significantly refactor your code base. But you will stick to finding facts and information that confirm your beliefs and actions. All these biases affect you in a similar way. You are resistant to changing your decisions and being flexible with technologies, and you avoid refactoring and incorporating new things into your codebase.</p><h3>Focus not only on your strengths but also on those areas you find less enjoyable and more difficult.</h3><p>You have that bug, that warning in your console that you know that you should have resolved for weeks now. You still prefer to work on new features, things that you know how to resolve, or on a nice frontend feature with great effects that will add a feeling to your website. But the important things that will enable you to grow as developer also include focusing on those tasks you do not find enjoyable at the moment, but that may bring rewards in the long run. When you resolve that warning, you will get much more insight into how things work at a deeper level. You usually know your libraries just superficially through prepared <em>APIs</em>, but by going after vital but less attractive tasks you will often need to dive into the library codebase. You will learn how other engineers work and what their coding style involves.</p><h4>Listen to others &amp; get a mentor</h4><p>Being on a team of people who listen to each other will increase your learning so dramatically that it is invaluable and irreplaceable. You will not just learn the skills of engineering, but also important social skills. If you are a complete beginner it may be difficult to start coding from scratch. You just do not know what you do not know. You will probably make many mistakes in focusing on things that do not matter that much, and it will cost you a lot of time. I would recommend that you join a team with more senior developers so you can ask for help, code reviews, etc. The most common problems in a team environment is that we often encounter a cognitive bias called the <em>IKEA effect</em> that can cause disputes between team members, especially if there are senior developers who have their egos attached to their code. The <em>IKEA effect</em> causes each member to not approach the solution to a problem objectively, and to overvalue their own solution and undervalue those of others. Once you are aware of this issue you can be more logical when you are discussing the best solution for the project with other team members.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uPujjWuPLN-2Z3d_TGNO0g.jpeg" /></figure><h3>Mitigating biases</h3><p>This is just a small subset of biases good to be aware of when learning programming. The best way to start mitigating the effect biases have on you and your decisions is to be aware of them and start to retrospectively see how they have affected your decisions and behavior. I would recommend you look at your past behavior and try to identify some cases in which you were in some sense biased. Try to remember the emotions that you were feeling, be aware of it and start calculating further decisions with that emotion. The key to reducing how much a bias affects you is to disassociate yourself from the feeling itself. Look at the feeling as an external object and evaluate the decisions you made based on real facts. If possible, rely on mathematics and calculating an expected value for each decision. Feelings are a good indicator in some cases, but are not entirely accurate. By injecting logic into your learning and work in general you will get much better results and you will be able to focus on key areas and avoid pitfalls — especially mistakes that lead you to continue working with old legacy tech stacks.</p><h3>Summary</h3><p>These are some of the biases and human tendencies that may hold you back in your progress as an engineer. I would say that it is most important to be flexible in adopting new technologies and not resistant to change while also prioritizing your tasks for long-term success. This will help you to adopt technologies faster, learn more lessons and, indirectly, will also help you increase your learning rate. By adopting new technologies more frequently you will see more codebases and you will “learn to learn” much more effectively. I believe that the ability to learn quickly is the most important skill for success, especially in engineering, as the amount of new technology and complexity of our systems is continually increasing.</p><blockquote>Did you like this post and want to learn more about React, GraphQL and Node.js or just Javascript in general? Connect with us through our newsletter below to get instant updates on more articles like this. If you would like to start right now, you can check out our upcoming <a href="https://graphqlmastery.com/course/graphql-language">GraphQL Language course</a>.</blockquote><p><em>Originally published at </em><a href="https://graphqlmastery.com/blog/how-to-learn-graphql-react-and-node-js-faster"><em>https://graphqlmastery.com/blog/how-to-learn-graphql-react-and-node-js-faster</em></a><em>.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F240011-2%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F240011-2%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/a47edab45a66dbcfd3af1657aacc2db1/href">https://medium.com/media/a47edab45a66dbcfd3af1657aacc2db1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdc95e8510c7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/atheros/how-to-learn-graphql-react-and-node-js-faster-bdc95e8510c7">How to learn GraphQL, React and Node.js faster</a> was originally published in <a href="https://medium.com/atheros">Atheros</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL List — How to use arrays in GraphQL schema (GraphQL Modifiers)]]></title>
            <link>https://medium.com/atheros/graphql-list-how-to-use-arrays-in-graphql-schema-graphql-modifiers-309d53b44c6e?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/309d53b44c6e</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Mon, 03 Sep 2018 10:12:57 GMT</pubDate>
            <atom:updated>2019-05-09T11:55:30.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiRlvrBDE0v9j81tC8PCVQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/Ai2TRdvI6gM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nattu Adnan</a> on <a href="https://unsplash.com/search/photos/beach?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>Introduction</h4><p>It is often common practice in REST APIs to return a JSON response with an array of objects. In GraphQL we would like to follow this pattern as well. In this article we will go through modifiers, a special group of types which allows us to modify the default behavior of other types. In GraphQL we deal with various groups of types. These groups are as follows:</p><ul><li><a href="https://medium.com/graphql-mastery/graphql-scalars-and-enums-part-1-built-in-scalars-overview-and-application-4a85f841698f">Scalars</a> and <a href="https://medium.com/graphql-mastery/how-to-design-graphql-queries-and-mutations-part-3-custom-scalars-78d441869258">custom scalars</a></li><li><a href="https://medium.com/graphql-mastery/graphql-scalars-and-enums-part-1-built-in-scalars-overview-and-application-4a85f841698f">Enums</a></li><li><a href="https://medium.com/graphql-mastery/setting-up-basic-graphql-server-in-node-js-with-express-c25eeaa819c2">Objects</a> and <a href="https://medium.com/graphql-mastery/json-as-an-argument-for-graphql-mutations-and-queries-3cd06d252a04">input object types</a></li><li>Abstract types — Interfaces and union types</li><li>Modifiers</li></ul><blockquote><a href="https://graphqlmastery.com/course/graphql-language">Checkout the upcoming <strong>free</strong> <strong>GraphQL language course </strong>with in browser exercices</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*K2kl-FlLs0dvGqXa.gif" /><figcaption>From upcoming <a href="https://graphqlmastery.com/course/graphql-language">GraphQL Language course</a></figcaption></figure><p>It may be helpful first to go through the articles above. After gaining a fundamental understanding of other types such as scalars and object types you can then move on to modifiers. Next we can start working on the project setup so that we can test our queries. We assume that <a href="https://yarnpkg.com/">yarn</a>, <a href="https://git-scm.com/">git</a> and <a href="https://nodejs.org/en/">Node.js</a> versions higher than 8 are already installed on your computer. Now you can execute this command in your shell</p><pre>git clone <a href="https://github.com/a7v8x/express-graphql-demo.git">https://github.com/a7v8x/express-graphql-demo.git</a> -b feature/5-modifiers</pre><p>and install dependencies with</p><pre>yarn install</pre><p>After that you should be able to run the GraphQL server with</p><pre>yarn run dev</pre><p>Then you can move to <a href="http://localhost:3000/graphql">http://localhost:3000/graphql</a> to execute the queries available in this article. In the model project, we use the “in-memory” database with fake data for executing our queries.</p><h3>Model schema</h3><p>Let’s first consider this model schema, which was printed with the <a href="https://graphql.org/graphql-js/utilities/#printschema">printSchema</a> function from graphql-js utilities. The model schema in the repository is built with a class-based approach using the graphql-js library. It is often much clearer to view the whole schema written in Schema definition language (SDL). For some time now, SDL has been a <a href="https://github.com/facebook/graphql/pull/90">part of the specification</a> and it is often used to build the schema itself using the buildschema utility or the library called <a href="https://github.com/apollographql/graphql-tools">graphql-tools</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d45633d0d089029de26169fb89e2d3f9/href">https://medium.com/media/d45633d0d089029de26169fb89e2d3f9/href</a></iframe><p>We can see that we have defined one output object type called <em>User</em> with the following fields: <em>id</em>, <em>username</em>, <em>email</em>, <em>phone</em>, <em>firstname</em>, <em>lastname</em>. The <em>id</em> field is typed as an <em>ID</em> scalar and other fields are typed as Strings. We’ve also defined the queries <em>user</em> and <em>users</em>. The user query returns the <em>User</em> object based on the passed id. The <em>users</em> query then returns a list of users. We have also defined the nonrequired enum type role, which is used in the users query as an argument for filtering the result. In this simple schema we used modifiers quite a lot. In the rest of the article we will go through these use cases.</p><h3>Modifiers</h3><p>First let’s formally define modifier. As we have already mentioned, modifier is a special group of types in <em>GraphQL</em>. These types can be defined as follows:</p><blockquote><em>A </em>Modifier<em> modifies the type to which it refers.</em></blockquote><p>From this definition it is clear that we always need to define the type to which we are applying the modifier. In current <em>GraphQL</em>specification, we have these two types of modifiers. Each of the modifier is classified as a separate type:</p><ul><li><strong>List</strong></li><li><strong>Modifiers</strong></li></ul><p>The list modifier will be our main focus in this article. It will allow us to define if we would like to return a sequence of types. A non-null modifier allows us to define if the type/field is required. This can be null (default behavior in GraphQL) or is required and the GraphQL server raises an error. In this article we will focus mainly on List modifiers and leave a more in-depth discussion of non-null modifiers for another article.</p><h3>List</h3><p>In general, a GraphQL list represents a sequence of values. It is possible to view these values as arrays (e.g. in Javascript), although the analogy is not completely precise. As we mentioned a list keeps items in order. In SDL the list modifier is written as square brackets with the wrapped instance of the type in the bracket. In our schema we used the list modifier to define that if we call the query users, it returns a sequence of types of User from the database. This is achieved by defining the schema as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2467a864a10c1320813ea0d54c2b15cc/href">https://medium.com/media/2467a864a10c1320813ea0d54c2b15cc/href</a></iframe><p>By calling query users we expect to return a list of users. Let’s see how this looks when we use the graphql-js library. The queries in our repository are defined as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed26359aa9786863134feb0c17748db5/href">https://medium.com/media/ed26359aa9786863134feb0c17748db5/href</a></iframe><p>We can see that we achieve the same functionality as with SDL. The GraphQLList class represents the List in graphql-js. We have applied the instance of this class to the instance of User. Now we are able to fetch the data by executing the users query in GraphQL playground with the “Play” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*OQDOm-jElzDp59hMRxClVg.png" /></figure><p>We should retrieve this data and obtain users as a list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32a240a8c8d341b72cf0ed058185a58d/href">https://medium.com/media/32a240a8c8d341b72cf0ed058185a58d/href</a></iframe><p>The other use case for <em>List</em> modifiers is for designing the <em>createUsers</em> mutation, where we can add users in batch. There are multiple reasons to design the mutations in this way. We may need to add <em>users</em> in transaction, therefore we cannot have a different resolver context or we just want to simplify the API or improve the performance and execute the mutation for multiple users more quickly. This is a great use case for applying the <em>List</em> modifier to our input payload. We can define the input object type just once like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe4036ab7e8918008e0805dffd57d36d/href">https://medium.com/media/fe4036ab7e8918008e0805dffd57d36d/href</a></iframe><p>or in SDL language</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37df5e46670a42d3583da52b8948e9c1/href">https://medium.com/media/37df5e46670a42d3583da52b8948e9c1/href</a></iframe><p>and then apply list modifier to achieve the ability of passing multiple payloads in one input variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22a56b87ca589dac42c3670c0c35d2d0/href">https://medium.com/media/22a56b87ca589dac42c3670c0c35d2d0/href</a></iframe><p>We can execute the mutation with using inline arguments or if you prefer with <a href="https://medium.com/graphql-mastery/graphql-quick-tip-how-to-pass-variables-into-a-mutation-in-graphiql-23ecff4add57">using variables</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9dec8d5c4afcc9966e45b738088c856/href">https://medium.com/media/f9dec8d5c4afcc9966e45b738088c856/href</a></iframe><p>Now let’s go through the rules for result and input coercion. If you are not familiar with these terms, you can take a look at the article on <a href="https://medium.com/graphql-mastery/graphql-scalars-and-enums-part-1-built-in-scalars-overview-and-application-4a85f841698f">scalars</a>, where we describe input and result coercion.</p><h3>Result coercion</h3><p>For the query users, result coercion is relevant for us as we would like to obtain an array of users from the executed query. When we coerce lists, the GraphQL server needs to ensure that the returned data from the resolver function will remain in the same order. The coercion of the each item in the list is then delegated to the result coercion of the referenced type; each item of the array needs to comply to User type or null value. If it returns an object instead of array like in this resolver function:</p><pre>users: {<br>   type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(User))),<br>   args: {<br>     role: {<br>       type: UserRoleEnum,<br>     },<br>   },<br>   resolve: async (source, { role }) =&gt; {<br>     const result = await getUsers();<br>     if (role) {<br>       return result.filter(user =&gt; user.role === role);<br>     }<br>     return {};<br>   },<br> },</pre><p>the GraphQL server should then raise this error</p><pre>Expected Iterable, but did not find one for field Query.users.</pre><p>This happens if the coercion of the List modifier does not comply But what happens if some of the items in the list do not coerce properly? In that case we handle the error in a similar manner. We return <em>null</em>instead of the value returned from the resolver function and add an error to the response.</p><h3>Input coercion</h3><p>When discussing input coercion of <em>List</em> modifiers we can take into account the <em>createUsers</em> mutation and describe the behavior that raises an error. In contrast to the result coercion, where some items from the result array can be obtained even if one item is not coerced properly, in input coercion we will not be able to execute the whole mutation if one payload cannot be coerced. Let’s take a look at the following example, where we would like to pass a list of two payloads, but one payload does not comply to the input type and does not have the required<em>username</em> field. Upon executing this mutation we receive the following error:</p><pre>Argument &quot;input&quot; has invalid value [{username: &quot;testtest&quot;, email: &quot;test@test.com&quot;, firstName: &quot;test&quot;, lastName: &quot;test&quot;}, {email: &quot;test@test.com&quot;, firstName: &quot;test&quot;, lastName: &quot;test&quot;}]. In element #1: In field &quot;username&quot;: Expected &quot;String!&quot;, found null.</pre><p>The whole mutation fails even if only the input coercion in the input object type in one item in the list does not comply. However, it is important to emphasize that if we pass null as follows, the whole mutation will be executed. However, this depends on whether or not we applied any additional modifiers and composed the modifiers in a more complex type. We will go through this topic in the last section of this article on <strong>Modifier composition</strong></p><h3>Modifier composition</h3><p>If we consider the definition of the modifier above, we know that the modifier basically creates a new type from the referenced type with additional functionality. In our case we are adding behavior so that the result coercion will accept a list of items and not just the item itself. This is also similar to higher order functions or the decorator pattern and in the same manner we can chain higher order functions or HOCs in React. We are also able to compose modifiers by applying a modifier to the type where the previous modifier is already applied. We can combine the Non-Null modifier with our List modifier in the following way. This way we basically combine three modifiers, which are chained as follows</p><pre>new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(User)))</pre><p>This creates a special type. When using only a list modifier we are allowed to return a null value from the resolver. We can even combine the items in the array to contain null values as in this array:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a707e50917021d82bf8b1bd60b60c9c/href">https://medium.com/media/1a707e50917021d82bf8b1bd60b60c9c/href</a></iframe><p>But when we apply the composed modifier as above, we are only allowed to pass the array containing the objects that comply to the <em>User</em> type. The list above will therefore be rejected. The <em>null</em> value returned from resolver will be also rejected. You can take a look at the table below, which contains what each modifier will allow in order to get a better idea of which combinations of modifiers are suitable for different use cases. The only rule in chaining modifiers applies to Non-null modifiers. It declares that we cannot wrap one Non-Null modifier with another Non-Null modifier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/713e2a0584a1e292c44f234837fb7298/href">https://medium.com/media/713e2a0584a1e292c44f234837fb7298/href</a></iframe><p><em>InvalidUserObject</em> in this table can be equal for example to</p><pre>{ <br>  lastName: &quot;Test&quot;,<br>  firstName: &quot;test&quot;,<br>  username: &quot;t1est&quot;<br>}</pre><p>For simplicity, i did not cover differences between input and output coercion for these more complex types. The behaviour is different only as we discussed in the result and input coercion section. If there would be different <em>UserObject</em>, which does not comply to <em>User</em> type coercion (e.g. does not have <em>username</em> property), there would be additional rules.</p><h3>Summary</h3><p>In this article we have covered one special group of types in GraphQL called <em>Modifiers</em>. With modifiers we are allowed to inject special behavior into the referenced GraphQL type, add a List and other required fields, and even combine these use cases to build more complex types. Modifiers are a great tool to make elegant GraphQL schemas.</p><blockquote>Did you like this post? The repository with the examples and project setup can be cloned from this <a href="https://github.com/atherosai/express-graphql-demo/tree/feature/5-modifiers">branch</a> on my <a href="https://github.com/a7v8x">GitHub account</a>. You can also subsribe in the form below and you will get early access to upcoming free <a href="https://graphqlmastery.com/">GraphQL course</a> and also get email, once new article on GraphQL Mastery is released.</blockquote><p><em>Originally published at </em><a href="https://graphqlmastery.com/blog/graphql-list-how-to-use-arrays-in-graphql-schema"><em>https://graphqlmastery.com/blog/graphql-list-how-to-use-arrays-in-graphql-schema</em></a><em>.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F240011-2%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F240011-2%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/a47edab45a66dbcfd3af1657aacc2db1/href">https://medium.com/media/a47edab45a66dbcfd3af1657aacc2db1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=309d53b44c6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/atheros/graphql-list-how-to-use-arrays-in-graphql-schema-graphql-modifiers-309d53b44c6e">GraphQL List — How to use arrays in GraphQL schema (GraphQL Modifiers)</a> was originally published in <a href="https://medium.com/atheros">Atheros</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL security in Node.js project]]></title>
            <link>https://medium.com/atheros/graphql-security-in-node-js-project-4a4d39a1df20?source=rss-452d0ada7367------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a4d39a1df20</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Mráz]]></dc:creator>
            <pubDate>Thu, 16 Aug 2018 07:01:01 GMT</pubDate>
            <atom:updated>2018-10-02T07:27:18.074Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pR4PYnwlPEUWiPcPq8CxuQ.jpeg" /></figure><h4>Introduction</h4><p><a href="https://graphql.org/">GraphQL</a> is a powerful tool, but with great power come great security risks. One of the biggest advantages of GraphQL is that you are able get data across multiple resources within a single request. This allows the potential attacker to make complex queries that quickly result in resource exhaustion. In this brief article we will go through some tips to minimize these risks and secure your GraphQL schema against potential attackers.</p><blockquote><a href="https://graphqlmastery.com/course/graphql-language">Checkout the upcoming <strong>free</strong> <strong>GraphQL language course </strong>with in browser exercices</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*K2kl-FlLs0dvGqXa.gif" /><figcaption>From upcoming <a href="https://graphqlmastery.com/course/graphql-language">GraphQL Language course</a></figcaption></figure><h4>Use https and do not forget about https redirect</h4><p>I would not say this issue is <a href="https://graphql.org/learn/">GraphQL</a> specific, but nearly all websites should use https. Moreover, you are communicating with the server in a more secure way. This will also improve your SEO. We often find that some developers forget to add https redirect or an hts header to your server. Then, if you access <a href="https://graphqlmastery.com/">http://graphqlmastery.com</a> you will be redirected to the https version and then communicate with the using http protocol by accident. If you use express it is also good practice from a security point of view to add <a href="https://github.com/helmetjs/helmet">helmet</a> middleware to existing server. This library will adjust headers in each request to be more secure.</p><h4>Disable <a href="https://graphqlmastery.com/blog/graphql-introspection-and-introspection-queries">introspection</a> in production</h4><p>If you are familiar with the tools like GraphiQL, you are maybe wondering, how you can know everything about the schema. In GraphQL there is an option to execute the so-called introspection queries of the schema. You can use this tool to know basically everything about the type system of the schema including, what you can query for, available mutations, etc. If you are in a development environment, it is definitely useful to allow introspection for various purposes. In production, however, it can leak important information for potential attackers or it will just reveal information about your new feature, which is not implemented on the fronted. If you want to solve this issue you can use the library called GraphQL <a href="https://github.com/helfer/graphql-disable-introspection">GraphQL Disable Introspection</a>. It allows you to add validation rules that disable introspection. To disable the introspection for everyone is sometimes a bit limited. Therefore it is much better to add introspection on per request bases or to enable introspection only for certain scopes.</p><h4>Masking errors</h4><p>When it comes to error handling it is helpful to have a clearly defined method to deal with errors in your GraphQL project. However, it is important to mask every error that users are not allowed to view. For example, if you use an SQL builder such as <a href="https://knexjs.org/">knex.js</a>, you can then reveal information about your database schema and leak important facts about the project structure to attacker. The proper way to do this is to add reactive middleware to your resolvers which enhances each resolver with masking functionality. A good library for that is <a href="https://github.com/thebigredgeek/apollo-resolvers">apollo resolvers</a> with a combination of <a href="https://github.com/thebigredgeek/apollo-errors">apollo errors</a>. With this design pattern you will not only implement masking errors, but you can also add additional permission logic. The other possibility is to add error masking to a format error callback in your <a href="https://github.com/apollographql/apollo-server">apollo server.</a> and use available errors in apollo server.</p><h4>Resource exhaustion prevention</h4><p>I think the biggest issue in GraphQL (especially if you want to open the schema to the public) comes with its biggest advantage, and that is the ability to query for various sources with a one single request. However, there are certain concerns about this feature. The issue is that potential attackers can easily call complex queries, which may be extremely expensive for your server and network. We can reduce the load on the database a lot by batching and caching with <a href="https://github.com/facebook/dataloader">Data Loader</a>. Load on the network, however, can not be reduced easily and has to be restricted. There are various ways to limit capabilities of the attacker to execute malicious queries. In my opinion, the most important and the most useful methods are the following:</p><ul><li><strong>Rejecting based on query complexity (cost analysis)</strong> great for public schema, but needed even for queries behind authorization. A great library for this use case is <a href="https://github.com/pa-bru/graphql-cost-analysis">graphql-cost-analysis</a> as it also provides different cost analysis rules based on the query and not just for the whole schema.</li><li><strong>Amount limiting</strong> restrict the amount of objects someone is able to fetch from the database. Instead of fetching every object, it’s better to use cursor based pagination.</li><li><strong>Depth limiting</strong> block recursive queries, which are too costly. Usually limiting the amount to depth 10 is good enough.</li></ul><p>There are many more methods you can implement, but the combination of these three you will cover most cases of malicious queries. None of these methods will solve the problem for every query. Therefore we need to implement a combination of these methods. We will include a detailed explanation with implementation in future articles, so be sure to subscribe.</p><h4>Use npm audit in your CI</h4><p>One of the biggest security issues in your Node.js project is that you can accidentally use a malicious package or a package with security holes. The danger exists not only for lesser known npm packages as described in <a href="https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5">this article</a>, but also for the packages with a large user base. Let’s take the example of the latest incident, which affected the package <a href="https://github.com/eslint/eslint-scope">eslint-scope</a>, which in turn is dependent on some widely used packages like <a href="https://github.com/babel/babel-eslint">babel-eslint</a> and <a href="https://github.com/webpack/webpack">webpack</a>, see <a href="https://eslint.org/blog/2018/07/postmortem-for-malicious-package-publishes">postmortem</a>. In this incident the the credentials of one of the the contributors were compromised, and then the new version of the packages with malicious code was published. You will never be able to defend yourself fully if you use some external packages, but you can significantly decrease the risk by using <a href="https://docs.npmjs.com/getting-started/running-a-security-audit">npm audit</a> in your continuous integration pipeline.</p><h4>Summary</h4><p>The list definitely does not end here. This is only a small subset of security concerns that you need to consider when deploying your GraphQL app to production. To really dive deeper into these topics with the practical code snippets on implementing all security concerns, you can subscribe to our GraphQL newsletter, where you will receive info about the newest articles on GraphQL Mastery and also updates on our upcoming GraphQL courses. Meanwhile, you can take a look at our free GraphQL language course.</p><p>Feel free to ask any question about the topic at <a href="/service/mailto:david@atheros.ai">david@atheros.ai</a> or in the comments below.</p><p><em>Originally published at </em><a href="https://graphqlmastery.com/blog/graphql-security-in-node-js-project"><em>graphqlmastery.com</em></a><em>.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F240011-2%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F240011-2%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/a47edab45a66dbcfd3af1657aacc2db1/href">https://medium.com/media/a47edab45a66dbcfd3af1657aacc2db1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a4d39a1df20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/atheros/graphql-security-in-node-js-project-4a4d39a1df20">GraphQL security in Node.js project</a> was originally published in <a href="https://medium.com/atheros">Atheros</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>