<?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 Piotr Mol on Medium]]></title>
        <description><![CDATA[Stories by Piotr Mol on Medium]]></description>
        <link>https://medium.com/@piotrmol?source=rss-b7ac7efe7b87------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kvv3wreQNjbmpqCGzhatlQ.png</url>
            <title>Stories by Piotr Mol on Medium</title>
            <link>https://medium.com/@piotrmol?source=rss-b7ac7efe7b87------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:46:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piotrmol/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[Wake Up to Better Grades: Harness Your Circadian Rhythms for Study Success]]></title>
            <link>https://medium.com/@piotrmol/wake-up-to-better-grades-harness-your-circadian-rhythms-for-study-success-577a794c12e0?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/577a794c12e0</guid>
            <category><![CDATA[circadian-rhythm]]></category>
            <category><![CDATA[studying]]></category>
            <category><![CDATA[internal-clocks]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 19:40:43 GMT</pubDate>
            <atom:updated>2024-07-08T19:40:43.904Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LugQVu7voN3re2vo" /><figcaption>Photo by <a href="https://unsplash.com/@allthestars?utm_source=medium&amp;utm_medium=referral">Sophie Dale</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Have you ever wondered what’s the best time to study for next week’s test? Should you get up early to study, or is it better to study in the afternoon? Or maybe stay up all night? When will you study more effectively? Will you be able to wake up on time tomorrow so you won’t be late for class? Will you hear the alarm? The answers lie in physiology. Our body, like a watch, has its own timing system known as circadian rhythms, a complex internal biological clock. It’s important for health and learning that the clock works perfectly. So important, in fact, that the scientists who discovered how circadian rhythms work were awarded the 2017 Nobel Prize in Medicine.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLx0LpFm-eMg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLx0LpFm-eMg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLx0LpFm-eMg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8902b95f35fe5f14f0f09724149c3613/href">https://medium.com/media/8902b95f35fe5f14f0f09724149c3613/href</a></iframe><p>I’m here to explain how the biological clock affects various aspects of our lives. Circadian rhythms are natural functions and behaviors that the body performs over a 24-hour cycle. They are regulated by the body’s internal clock and influenced by various external signals such as light and temperature. Think of your body as a symphony orchestra, with each organ and system playing its own instrument. Circadian rhythms act as the conductor, ensuring that each instrument plays in harmony and at the right time. They synchronize our bodily functions with the outside world, allowing us to adapt and thrive in an ever-changing environment. These rhythms influence not just our sleep but also our alertness, metabolism, and mood, all crucial for effective learning.</p><p>Believe it or not, all of this is happening in your body right now without you even realizing it. As a student, it’s important to be aware of this because, during adolescence, sleep hours tend to decrease as independence increases, and some rules about sleep or study schedules may be violated. Circadian rhythms also affect our ability to learn and remember. Studies have shown that circadian rhythms can affect the synchronization of optimal study periods. Therefore, aligning your schedule with your natural rhythms can improve your educational or professional performance.</p><p>When it comes to learning, our brain’s ability to absorb and process new information is not constant throughout the day. Certain periods of our circadian cycle have been found to be more conducive to learning and retaining new knowledge. These periods, often referred to as learning peaks, can vary from person to person. By identifying our individual learning peaks, we can strategically plan our study sessions or training activities to maximize their effectiveness.</p><p>Why? Because your creativity actually peaks at different points in that 24-hour cycle too. So, if you’re a student looking for those genius ideas, pay attention to when your mind feels most inspired during the day. The key is getting your daily routine locked down. When you have regular commitments like school, exercise, and hanging out with friends that happen at the same time each day, your body picks up on that pattern. It’s like an internal conditioning process. Before you know it, your rhythms will be so tuned in that you will find yourself waking up right before your alarm or feeling hungry just because it’s your usual mealtime.</p><p>Despite possible disruptions, it is possible to take steps to improve the health of circadian rhythms and consequently increase productivity and learning. Stick to a schedule: wake up and go to bed at the same time each day. Keep a balance between your daily activities and your nighttime rest. Create a dark environment for sleeping: use blinds or blackout curtains, or find a way to keep sunlight out of the windows. Do whatever it takes to make it feel like it’s night when it’s daytime. Try to spend at least two hours in natural sunlight. Soak up that vitamin D straight from the sun to strengthen your immune system and ward off future illnesses. Lastly, set healthy limits for yourself, such as avoiding texting, phone use, TV, or computers during bedtime or once you’re comfortably settled in bed. Your body’s natural rhythm will appreciate it.</p><p>Circadian rhythms play a crucial role in optimizing our study habits and overall health. By understanding and adapting to these natural cycles, we can enhance alertness, improve memory retention, and maintain a healthier lifestyle. Harness these insights to plan your study sessions and daily activities for peak efficiency.</p><p>Thank you for reading, and see you next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=577a794c12e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master Difficult Concepts]]></title>
            <link>https://medium.com/@piotrmol/master-difficult-concepts-50da848c9cfc?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/50da848c9cfc</guid>
            <category><![CDATA[feynman]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[student-tips]]></category>
            <category><![CDATA[fast-learning]]></category>
            <category><![CDATA[feynman-technique]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 07:56:19 GMT</pubDate>
            <atom:updated>2024-04-12T07:56:44.907Z</atom:updated>
            <content:encoded><![CDATA[<h3>Master Difficult Concepts: A Step-by-Step Guide to the Feynman Technique</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_hjoHxuepNErCmFo" /><figcaption>Photo by <a href="https://unsplash.com/@alandelacruz4?utm_source=medium&amp;utm_medium=referral">ALAN DE LA CRUZ</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Ever spent a whole week buried in books, pulling all-nighters, only for your mind to go blank the moment an exam paper stares back at you? You’re not alone; it’ has happened to me too. But we’re not doomed to repeat this. Let me introduce you to the Feynman Technique, a strategy that will drastically boost your success rate in learning.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fs-px2R0ugwk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Ds-px2R0ugwk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fs-px2R0ugwk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3877d40373bddb595793e08476b20b91/href">https://medium.com/media/3877d40373bddb595793e08476b20b91/href</a></iframe><p>This technique was pioneered by Nobel Prize-winning physicist Richard Feynman. At its core, the Feynman Technique simplifies the learning process into four simple steps that emphasize understanding over rote memorization. Here’s how it breaks down:</p><p><strong>Step 1: Study</strong> — The first step is all about immersion. Select a concept you’re curious about and dive into learning. Use every resource at your disposal — books, articles, lectures, videos — to gain a comprehensive understanding of the topic. The aim here is to build a solid foundation of knowledge, setting the stage for deeper exploration and understanding</p><p><strong>Step 2: Teach It</strong> — Now, take what you’ve learned and explain it as if you were teaching someone with no prior knowledge of the topic, like a young child. Simplify your explanations, use analogies, and draw from everyday experiences. This isn’t just about teaching; it’s about ensuring you truly understand the concept yourself. If you struggle to simplify, it’s a sign to revisit your understanding.</p><p><strong>Step 3: Review and Refine</strong> — As you attempt to teach the concept in simple terms, you’ll inevitably encounter areas where your explanation n . These stumbling blocks are gold mines for insight. They pinpoint exactly where your understanding is incomplete. Note these gaps and go back to your study materials. Dive deeper into these specific aspects, seeking clearer explanations and better analogies. The goal here is to solidify your grasp on the concept, turning weak points into strengths.</p><p><strong>“Step 4: Simplify and Connect</strong> — The last step is about refining your explanation to make it even simpler and more connected to real-world examples. After addressing the gaps in your knowledge, revisit your explanation. Can you simplify it further? Can you relate it to everyday experiences or commonly understood concepts? This process not only deepens your understanding but also enhances your ability to communicate the concept effectively to others</p><p>And that’s the Feynman Technique: a straightforward method to deepen your understanding and sharpen your learning skills. Give it a try, and watch how it transforms your study habits.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50da848c9cfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memorize Like a Genius]]></title>
            <link>https://medium.com/@piotrmol/memorize-like-a-genius-the-mind-palace-technique-5f3b44736b3a?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f3b44736b3a</guid>
            <category><![CDATA[memory-improvement]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[fast-learning]]></category>
            <category><![CDATA[academic]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Mon, 25 Mar 2024 13:22:39 GMT</pubDate>
            <atom:updated>2024-03-25T13:26:53.668Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Mind Palace Technique</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o5E2EleMqX7z85te" /><figcaption>Photo by <a href="https://unsplash.com/@_dorian_?utm_source=medium&amp;utm_medium=referral">Dorian Mongel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Have you ever been amazed by those memory champions who can recall hundreds of numbers or words with ease? Well, it’s not magic — it’s a technique anyone can learn: the Memory Palace, also known as the Loci Method.<br>This ancient Greek method completely transforms how you store and retrieve information. It makes memories vivid, long-lasting, and most importantly, easy to access!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F3yo2c-l5h4I%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D3yo2c-l5h4I&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F3yo2c-l5h4I%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d161770568196878f48a509823be76b4/href">https://medium.com/media/d161770568196878f48a509823be76b4/href</a></iframe><p>So, how does this mind palace technique work? The secret lies in our brain’s built-in spatial memory and its astonishing ability to recall vivid, out-of-the-ordinary images. By leveraging these natural capabilities, the Loci method enhances our memory like never before.</p><p>Let’s dive into how you can harness this technique using a simple example: memorizing a shopping list.<br>First, select a familiar place to construct your memory palace.</p><p>Imagine your home, with its rooms and furniture, as the backdrop for this exercise.<br>Next, identify specific locations within your palace to act as memory stations. The couch in your living room, the dining table, and the fridge are all perfect examples.</p><p>Now, let’s get imaginative with our shopping list items. Suppose your list includes milk, bread, and apples. Here’s how you might visualize each item:</p><p>For milk, picture a cow sitting on your couch, casually flipping through TV channels with a remote in its hoof. This absurd visual is sure to embed the need for milk in your memory.<br>Imagine a loaf of bread lounging on your dining table, sunbathing under a lamp, wearing sunglasses. This creates a memorable scene for remembering bread.<br>For apples, envision a group of apples performing a circus act, juggling each other in your fridge. This unusual performance is hard to forget.<br>To recall your shopping list, mentally walk through your memory palace, visiting each station.</p><p>By associating day-to-day items with engaging, vivid images placed in a familiar location, you tap into your brain’s spatial memory and capacity for recalling vivid imagery. This not only strengthens your memory but turns the act of remembering into an imaginative adventure</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f3b44736b3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Node.js App on AWS Cloud in a Serverless Way]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/deploying-node-js-app-on-aws-cloud-in-a-serverless-way-d889a9444ef7?source=rss-b7ac7efe7b87------2"><img src="https://cdn-images-1.medium.com/max/2600/0*AmvWFtv3jY7o8DRt" width="7952"></a></p><p class="medium-feed-snippet">Learn how to use App Runner with RDS service</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/deploying-node-js-app-on-aws-cloud-in-a-serverless-way-d889a9444ef7?source=rss-b7ac7efe7b87------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/deploying-node-js-app-on-aws-cloud-in-a-serverless-way-d889a9444ef7?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/d889a9444ef7</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Wed, 11 Jan 2023 22:33:49 GMT</pubDate>
            <atom:updated>2023-01-11T22:33:49.235Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Improve Your Content Delivery Using AWS Lambda@Edge]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/improve-your-content-delivery-using-aws-lambda-edge-1c9815f5527f?source=rss-b7ac7efe7b87------2"><img src="https://cdn-images-1.medium.com/max/2600/0*4GZpDfpTCABqw2gQ" width="5184"></a></p><p class="medium-feed-snippet">Learn how to attach Lambda functionality to your CloudFront distribution</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/improve-your-content-delivery-using-aws-lambda-edge-1c9815f5527f?source=rss-b7ac7efe7b87------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/improve-your-content-delivery-using-aws-lambda-edge-1c9815f5527f?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c9815f5527f</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Mon, 27 Jun 2022 15:57:29 GMT</pubDate>
            <atom:updated>2022-06-27T15:57:29.035Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[AWS DynamoDB Global Secondary Indexes]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/aws-dynamodb-global-secondary-indexes-3ee7f6d8da0?source=rss-b7ac7efe7b87------2"><img src="https://cdn-images-1.medium.com/max/2600/0*gV7k0iXiFr617zjJ" width="4752"></a></p><p class="medium-feed-snippet">Extend your access patterns with ease</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/aws-dynamodb-global-secondary-indexes-3ee7f6d8da0?source=rss-b7ac7efe7b87------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/aws-dynamodb-global-secondary-indexes-3ee7f6d8da0?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ee7f6d8da0</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Tue, 07 Jun 2022 13:31:57 GMT</pubDate>
            <atom:updated>2022-06-07T13:31:57.209Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[AWS Pricing Calculator in 10 minutes]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/better-programming/aws-pricing-calculator-in-10-minutes-9e3e46f40f82?source=rss-b7ac7efe7b87------2"><img src="https://cdn-images-1.medium.com/max/2600/0*rXUtbzOgZoM6yoP6" width="5472"></a></p><p class="medium-feed-snippet">Estimate your cloud costs</p><p class="medium-feed-link"><a href="https://medium.com/better-programming/aws-pricing-calculator-in-10-minutes-9e3e46f40f82?source=rss-b7ac7efe7b87------2">Continue reading on Better Programming »</a></p></div>]]></description>
            <link>https://medium.com/better-programming/aws-pricing-calculator-in-10-minutes-9e3e46f40f82?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e3e46f40f82</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-pricing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Fri, 27 May 2022 15:50:15 GMT</pubDate>
            <atom:updated>2022-05-27T15:50:15.920Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[GraphQL for Node.js developers, pt. 3 — error handling]]></title>
            <link>https://blog.devgenius.io/graphql-for-node-js-developers-pt-3-error-handling-37f7e96f3608?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/37f7e96f3608</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[error-handling]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Tue, 17 May 2022 20:36:50 GMT</pubDate>
            <atom:updated>2022-05-17T20:36:50.750Z</atom:updated>
            <content:encoded><![CDATA[<h3>GraphQL for Node.js developers, pt. 3 — error handling</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vQ9bH86FE6glm17f" /><figcaption>Photo by <a href="https://unsplash.com/@remyloz?utm_source=medium&amp;utm_medium=referral">Remy_Loz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We all make mistakes. The thing is, how do we manage to handle them. The same is applicable to ours API. There will be errors, for sure. We have to be prepared to handle them. So in this tutorial, I will teach you how to work with errors in GraphQL APIs. Just grab a cup of coffee and follow me along.</p><p>The errors in GraphQL are handled differently in comparison to the rest APIs. GraphQL does not rely on HTTP statuses for informing about errors. Instead, the values returned inside the response body tell us about success or failure. There are two keys inside that body: data and errors. If one error or more has occurred, they will be present inside the errors array. So from a client perspective, to verify if something bad happened, you have to check if the errors array is not empty.</p><p>So, let’s demonstrate it in practice. First, I’ll start with a basic case. Suppose there is an error in the query. For example, I have mistyped the name __typename. What will be returned from API then? In this scenario, the apollo server will return an error deriving from ApolloError class and having code equal GRAPHQL_VALIDATION_FAILED It is one of predefined the apollo server’s errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPT0JFtnTSufhCGrAbKfcg.png" /><figcaption>Apollo Server error</figcaption></figure><p>You can check all possible error codes here in the apollo documentation:</p><p><a href="https://www.apollographql.com/docs/apollo-server/data/errors/#error-codes">Error handling</a></p><p>Besides the error code, the error object contains an error message and stack trace. The stack trace is useful for debugging, but it shouldn’t be included in the production environment. To disable stack trace in error messages, you have to set the NODE_ENV variable to production or test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hp1Nz3tQPJqknJkmV75Dsw.png" /><figcaption>Setting the NODE_ENV</figcaption></figure><p>Then, the stack trace is not exposed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnGX5mHYf_i7E40HWDtclA.png" /><figcaption>Error without stack trace exposed</figcaption></figure><p>Apollo Server throws errors of most built-in types automatically when applicable. For example, it throws a ValidationError whenever an incoming operation isn’t valid against the server’s schema. There are some cases when you don’t want to expose actual errors to the client. For example, maybe the error message contains confidential information, or it’s just meaningless to the client. In such cases, it is good to override the final error message. For that, there is a handy method you can use. The apollo server constructor may take the formatError callback as an input parameter. The callback function takes only one parameter, which is the error. You can do with it whatever you want until the callback returns some error.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FLmCYGjPpr1SDS6FqZX%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FLmCYGjPpr1SDS6FqZX%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FLmCYGjPpr1SDS6FqZX%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="355" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d0d8eaebea303b2b94511f640713bd7/href">https://medium.com/media/8d0d8eaebea303b2b94511f640713bd7/href</a></iframe><p>For example, let’s imagine that a database error has occurred. First, you have to catch the error because it contains some scheme-specific details, and it may be dangerous to expose such information. Then you’d like to return the generic Internal Server Error. For that, let’s create a callback function taking the error as input. First, check if typeof error is DatabaseError in the callback. If so, return a new error containing a generic message; otherwise, return the error without change. Now pass the callback to the apollo constructor. It has to be added under the key formatError .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1f8b64904428b072927d29bf782578e/href">https://medium.com/media/a1f8b64904428b072927d29bf782578e/href</a></iframe><p>And that’s it. Now, those specific errors won’t be exposed to the user. So far, so good. But are there any best practices on how to handle errors with GraphQL? Of course, they are. But to do it properly, we have to start from the beginning. The GraphQL schema has to be designed to support good error handling. It will be based on the interfaces and union types. In my previous tutorial, I created a few queries and mutations for managing Movies API.</p><p><a href="https://blog.devgenius.io/graphql-for-node-js-developers-pt-2-unions-and-interfaces-772b7bbf761f">GraphQL for Node.js developers, pt. 2 — Unions and Interfaces</a></p><p>Let’s extend that example to one more query. Let’s create a getMovieById query. The query may return a movie or two kinds of errors — MovieNotFoundError or InvalidMovieIdError . I will create the interface called BaseErrorand set the message to be required. Next, I will add two implementations of the interface and I will create the union type called GetMovieByidResult. Union will return the Movietype or MovieNotFoundError or InvalidMovieIdError. The last thing to do is to create the query. Here, you can see the final query definition:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc25d738d6d559484adf3b15791d26a8/href">https://medium.com/media/dc25d738d6d559484adf3b15791d26a8/href</a></iframe><p>Let’s see how the usage of union will affect the resolver. The getMovieById resolver function checks if the id is typeOf number. If no, there is a validation error (<em>I&#39;m aware that’s a silly case, but I’d like to show you how to work with the errors </em>😅 .) Next, it checks if there is a movie with a specific id. If no, there is a movie not found error. Lastly, if there is a movie, the function returns the movie. <strong>The important thing here is that you have to use the </strong>__typename<strong> variable and specify the return type. </strong>Apollo server must know which type was returned by the resolver.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71315e4b081583a951d6fce330bf4e3b/href">https://medium.com/media/71315e4b081583a951d6fce330bf4e3b/href</a></iframe><p>With the resolver function ready, you can test it out in the apollo studio. The frontend query also has to distinguish between returned types. Again, let’s use the __typename variable to achieve that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZ_4RZoRylDD7W4vLxhlRQ.png" /><figcaption>GraphQL query with error handling</figcaption></figure><p>So, that’s it for today. Great work! You have learned how to deal with GraphQL’s errors. Now you can distinguish errors from the actual data, and you can hide the sensitive information. At the end of the article, I placed the full code of today’s lesson. You can review it to summarize what you have learned.</p><p>Please consider following me so as not to miss the next article. Next time I will be talking about GraphQL resolver context object. <strong>Have a great day!</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ef6cf0e25b3d626627fb96f4b3f9880/href">https://medium.com/media/8ef6cf0e25b3d626627fb96f4b3f9880/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37f7e96f3608" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/graphql-for-node-js-developers-pt-3-error-handling-37f7e96f3608">GraphQL for Node.js developers, pt. 3 — error handling</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GraphQL for Node.js developers, pt. 2 — Unions and Interfaces]]></title>
            <link>https://blog.devgenius.io/graphql-for-node-js-developers-pt-2-unions-and-interfaces-772b7bbf761f?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/772b7bbf761f</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Mon, 11 Apr 2022 08:39:52 GMT</pubDate>
            <atom:updated>2022-04-11T08:39:52.251Z</atom:updated>
            <content:encoded><![CDATA[<h3>GraphQL for Node.js developers, pt. 2 — Unions and Interfaces</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B7Z8nIHe906HXB6p" /><figcaption>Photo by <a href="https://unsplash.com/@ricaros?utm_source=medium&amp;utm_medium=referral">Danial Igdery</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Good schema design is crucial for creating the best GraphQL APIs. For that, you have to know all available tools. In addition, you have to know from the inside out the GraphQL schemas. This article will help you understand the abstract data types — Unions and Interfaces. The article is the second part of the series explaining the concepts of GraphQL. You can find the first part here:</p><p><a href="https://medium.com/@piotrmol/introduction-to-graphql-for-nodejs-developers-5eb10240d38">Introduction to GraphQL for NodeJS Developers, pt. 1</a></p><p>I will start with a quick disclaimer about the last lesson. If you are interested only in interface and unions, please skip two paragraphs to follow along. So in the previous study, I created two queries and one mutation. To be honest, the createMoviemutation is not perfect. It takes five parameters:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f118beef0484ef25f6c82518e42081c/href">https://medium.com/media/4f118beef0484ef25f6c82518e42081c/href</a></iframe><p>In such scenarios, it is a good practice to create a wrapper object. To do so, you have to use the built-in GraphQL type input. The inputtype works almost exactly the same as the usual type.One difference is that it can be only used in the context of input parameters. You cannot set the input type as the return type. That would be silly 😏 So on the code below, you can inspect the improved version of mutation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58d8b08f7ffd7160d7a949fa6fbf2133/href">https://medium.com/media/58d8b08f7ffd7160d7a949fa6fbf2133/href</a></iframe><p>I have just wrapped the input parameters inside the input object. So now, the definition of mutation is much cleaner. The next thing I did was refactor of the mutation implementation. In the old implementation, I had the input properties unwrapped directly. Currently, I’m unwrapping the input variable from the createMovie method parameters. So that was only a disclaimer to the last lesson. Let’s move to more exciting topics 🎉 .</p><p>Now, we will be talking about unions and interfaces. Both are abstract types, which means you do not create their implementations directly. Instead, they describe some expected behavior. The union type is an aggregation of two or more types. In other words, it works as an OR operator. So if the query returns some union type, it can return type X or type Y. But you may ask: for God’s sake, why do I need something that doesn’t tell me precisely what I will get?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3cXmze4Y8igXdnkc3U%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3cXmze4Y8igXdnkc3U%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZDhheTM2cXc0dTcxdXd5eHd4Y3R0Nmd5YXhvZm45ejNkNGxyMWk0biZlcD12MV9naWZzX2dpZklkJmN0PWc%2F3cXmze4Y8igXdnkc3U%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc5091c083842830c92387c92334b771/href">https://medium.com/media/dc5091c083842830c92387c92334b771/href</a></iframe><p>The unions are so helpful in implementing searching functionality. For example, imagine that you have an API that serves movies and books to the user. On your website, you added a search bar. When the user types some search phrase, your API will search for the movies and the books containing such text. Then, the API response may include movies OR books. You see, here we are. Unions are useful 😄</p><p>So now, let’s see it for yourself. But first, let’s implement the same functionality. Since our last lesson, I have added a new JSON file containing a list of books. I also imported books array to script and prepared the type for books. It consists mainly of strings. However, there are two integers as well. You can check it on the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9264bfef51598401f4312bb71e8aa944/href">https://medium.com/media/9264bfef51598401f4312bb71e8aa944/href</a></iframe><p>Having the Booktype added, you are ready to move-on on our GraphQL types journey. To implement the searching functionality, you have to add the new union type to the typeDefsobject. Let’s call it SearchResultand set its return type to be Movieor Book.Then, you will add a new query to the schema. You can inspect the schema on the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91b7d884963213bb5e8adda54d1f22f8/href">https://medium.com/media/91b7d884963213bb5e8adda54d1f22f8/href</a></iframe><p>The next task is to provide an implementation of the search query. As with any other resolver function, it takes four arguments. But, again, we’ll be focused only on the second one, which is input. Based on the input, the code search for the desired phrase inside the movies and books arrays and returns matched objects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f4b13bbb370dde9d73d3a3968cd278f/href">https://medium.com/media/8f4b13bbb370dde9d73d3a3968cd278f/href</a></iframe><p>With the search function added to resolvers, you are almost ready. There is one crucial point. The union type is abstract. Apollo server has to know how to distinguish between concrete types of union. You have to teach the Apollo how to deal with your types. It’s an easy-peasy task :) You must add another key to your resolversobject, and it has to match the exact name of the union. In this case, it is a SearchResult name. Then you have to provide the callback function called __resolveType. As an input parameter, it takes a plain JavaScript object. Based on the received object, you have to return a string with the name of the object class. It’s a simple check. In our case, we know that the object is a Movieif it contains a plot.Only the movies contain the plot. Secondly, the object is the Bookif it contains a pages property. That’s it. You have implemented all the necessary pieces. You can review them in the code snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/297d27529bcc10ca166c79ec4795ecff/href">https://medium.com/media/297d27529bcc10ca166c79ec4795ecff/href</a></iframe><p>Let’s move to the apollo studio and check it in practice. I have created an example query for you. It’s similar to queries you have seen before. There is a name and input parameter. The difference lies in the way we pick the properties of the object. Because the query may return two different types, you have the option to select other parameters. The syntax is to put three dots, on keyword, and the type name. Next, inside curly braces, specify what to get from that type. There is one good practice here. Usually, adding a __typename variable to the query is a good practice. Check it on the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd424bf81cfeae2b707f46e67a1773b6/href">https://medium.com/media/dd424bf81cfeae2b707f46e67a1773b6/href</a></iframe><p>When executing the query, depending on the search phrase, you may expect a similar result to mine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XwCBmJfJrEfzOlIQZL1sw.png" /><figcaption>Search query result</figcaption></figure><p>Great, now you know how to deal with the union types. It’s a solid piece of information. Be proud of yourself ! Now we’ll have a quick look at interfaces. But knowing the unions, it will be so easy. Let’s start from the beginning. The interfaces are simple contracts. You create the interface when you want to make multiple types containing a common piece of information. You cannot create an instance of the interface. Instead, some concrete type has to implement that interface functionality. To illustrate that, let’s create an interface called FeaturedProducts. It will only have one requirement — it will require the product to have a title. Both types Movie and Book have the title field. You’d refactor the schema and set those types implementing the FeaturedProductsinterface. Now you can create a new query to check interfaces in practice.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8332cae76871d9ae22bb393b346fbc56/href">https://medium.com/media/8332cae76871d9ae22bb393b346fbc56/href</a></iframe><p>I’ll implement some dummy logic in the resolver function — I’ll return the first objects from movie and book arrays. The logic of finding the best products, it’s not the case here. What is interesting is the return type of mutation. Here, the function returns any type which implements the interface FeaturedProducts.<br>The interfaces, precisely the same as unions, require us to provide the __resolveType method. But there is another way of describing what type is returned. You can do this by setting the __typenamefield for returning the object inside such object. Sometimes the second approach is enough. Check it in the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/842d8b282149a0099d808fc74a4d3694/href">https://medium.com/media/842d8b282149a0099d808fc74a4d3694/href</a></iframe><p>Lastly, let’s execute the query and determine if it works correctly. I will pick the __typenameand title variable from each type. You can see the result of the query here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFg66MxPOQu-vRPQP6ew1Q.png" /><figcaption>FeaturedProducts query result</figcaption></figure><p>So that’s it for today. Great work! You have learned how to deal with GraphQL’s abstract types. Now you are two steps farther in the GraphQL journey. At the end of article, I placed the full code of today’s lesson. You can review it to summarize what you have learned.</p><p>Please, consider following me so as not to miss the next article. Next time I will be talking about GraphQL error handling. <strong>Have a great day!</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e362cbb4d466e96bf728eb06ba21b64b/href">https://medium.com/media/e362cbb4d466e96bf728eb06ba21b64b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=772b7bbf761f" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/graphql-for-node-js-developers-pt-2-unions-and-interfaces-772b7bbf761f">GraphQL for Node.js developers, pt. 2 — Unions and Interfaces</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to GraphQL for NodeJS Developers, pt. 1]]></title>
            <link>https://blog.devgenius.io/introduction-to-graphql-for-nodejs-developers-5eb10240d38?source=rss-b7ac7efe7b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/5eb10240d38</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Piotr Mol]]></dc:creator>
            <pubDate>Tue, 05 Apr 2022 09:25:04 GMT</pubDate>
            <atom:updated>2022-04-11T08:39:47.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="GraphQL — introduction for node developers banner photo" src="https://cdn-images-1.medium.com/max/1024/1*pbxinSpnD2NsOIc3qxMbJA.png" /></figure><p>Have you ever heard the phrases “GraphQL” or “GraphQL API” but don’t know it? Or maybe You know what it is, but you have no clue how to start working with it? Or maybe you don’t know if it’s a good fit for your API? If so, you are in the right place. In this article, I will explain the basic concepts of GraphQL. It’s the first article from a series of articles setting you up and ready to work with the GraphQL as NodeJs developer.</p><p>So what the heck is GraphQL, and why should you even care? GraphQL it’s just a query language for exchanging data between client and server. It is built upon an HTTP protocol. When using GraphQL API, you control what you are exactly fetching. In REST APIs, you always receive the whole model, even if you only need a part of it. In GraphQL, you, as the client, decide what to fetch. If you require data from two separates models? No problem, you can fetch them in one query. GraphQL optimizes data exchange over the network.</p><p>With that knowledge, we are ready to jump right into the code. <br>But, what will we be building? Let’s start with something simple. Imagine you have some movie database. Our goal is to create an API for querying the movies and adding new ones. I won’t bother you with databases related stuff. I’ll simply mock the data and be focused on GraphQL itself.<br>I have prepared a JSON file containing our mocks. It has two keys: “movies” and “genres.” Both are arrays. You can see it in the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5e87f08c1e63903492a6a55d4db902a/href">https://medium.com/media/e5e87f08c1e63903492a6a55d4db902a/href</a></iframe><p>I’ll start with the initialization of the node project. For this demo, I will use two packages — apollo-server and nodemon. Apollo-server it’s one of the implementations of the GraphQL standard for servers. In my opinion, it is one of the best. It has a broad community, excellent documentation, and a built-in client for testing API.</p><pre>npm init -y</pre><pre>npm i apollo-server nodemon</pre><p>To create GraphQL API, you need an ApolloServerclass and gqlmethod from the apollo package. gqlis a helper method for defining the GrapQL Schema. You can think of GraphQL schema as of database schema. We, as programmers, define them to describe what our model look-like. Then the client can freely query them without any restrictions. But schema itself is not all. To have a fully functional API, you need to create resolvers. In other words, you have to tell ApolloServer how to fetch or update a specific model from the system. I will move to resolvers later. Let’s focus on schema first.</p><p>In the example below, you can see our first schema definition:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73fdd26360a32e70e6e556715ea2cf7a/href">https://medium.com/media/73fdd26360a32e70e6e556715ea2cf7a/href</a></iframe><p>The variable name for my schema is typeDefs. It’s a naming convention for that. The schema is created by invocation of gqlmethod. You must use the typekeyword and give a descriptive name to provide a type definition. Inside the curly braces, you can define the type’s properties. To do that, provide the variable name, and after a colon, set a type.</p><p>The type might be scalar, enum, or Object. For example, the move type has an id property, which may be defined as the GraphQL ID type. The GraphQL Ids are serialized strings that uniquely identify the objects. Next, set a title as a string, year as an integer, runtime as a float, plot as a string, and genres as an array of strings. It’s worth mentioning that in GrahpQL, <strong>all properties are treated as optional</strong>.</p><p>In the next step, you have to define the query. Yes, in GraphQL, queries are defined inside schema. But you have told me that clients can query data freely. So you have lied to me!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*0ZgbUzfSordArY_EngNQ6g.jpeg" /></figure><p>The clients can query the data freely, which means they can decide what properties of the model they are interested in. Moreover, they can choose to query two, three, or more models in one single query. This is not possible in REST API. Remember, I compare the GraphQL API to REST API, not SQL query!</p><p>Going back to queries… The Query inside the schema definition is like the interface definition. It’s an abstraction, not implementation. You define query name, return type, and input parameters optionally. You can see it in the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bef746693265c527f492f0ea6d5a8448/href">https://medium.com/media/bef746693265c527f492f0ea6d5a8448/href</a></iframe><p>What you have done until now it’s just a simple schema definition. But, as I mentioned before, the schema is only one part of the puzzle. Besides the schema, you have to tell GraphQL how to resolve the queries. For that, you need a resolver function. The resolver function must match the name defined inside the schema definition. You can think of it as the interface implementation. You can check my resolver implementation in the example below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2effc64cf57adc79f418b9fa6bc32a57/href">https://medium.com/media/2effc64cf57adc79f418b9fa6bc32a57/href</a></iframe><p>In the getMoviesresolver, I return the mocked movies from my JSON file. Typically, here you’d see the calls to the database or other API.</p><p>Having the typeDefsand resolversset, you’re finally ready to start our server. I think the code for that is self-descriptive. Nothing fancy here :) <br>To start the actual server, type the below command in the terminal:</p><pre>nodemon index.js</pre><p>When you open the URL printed inside the console, you’ll be redirected to the apollo studio page. Apollo studio is a great tool for testing APIs. It’s made of three main sections. On the left-hand side, you can see documentation of your API. All your queries and types are there. In the middle, you have the test editor for writing the queries, and finally, on the right-hand side, there is a response section. I encourage you to play with it for a while. Please get familiar with it. When you implement GraphQL API, you will use it a lot.</p><p>To test if the query works as expected, I have created one for you:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f33564318e9bf0c3b7ab90029c8f2e84/href">https://medium.com/media/f33564318e9bf0c3b7ab90029c8f2e84/href</a></iframe><p>To fetch something from GraphQL API, you must use the keyword queryNext, you have to provide the name for the query. It’s only the name for the client — to distinguish between many more, you’d add :) <br>Inside the query object, you specify which queries you want to fire from the queries available on the server. And finally, inside the curly braces, define which properties of an object to fetch. As you may notice, the Movie schema has many more properties than I expected to get. With GraphQL, you have a choice. Great, the result of the invocation of such query should be as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*reQqotk4jprJmC8omn2WIw.png" /><figcaption>getMovies query result</figcaption></figure><p>That’s great, but to see the true power of GraphQL, I’ve created another query for you. The query is returning a list of genres :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1fdfae97b8354d040f09f7154592c0b/href">https://medium.com/media/a1fdfae97b8354d040f09f7154592c0b/href</a></iframe><p>Imagine that in your client app, you have a list of movies. You could potentially add the filtering feature. To do that, you need two things — a list of films and the list of filters. I want the app to be capable of filtering by movie genres. So you’ll fetch the movies from API and filters(genres) from API. If using rest? You call API two times. If using GraphQL — only one!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfYG3ZWrcerwjaVq_Qn9Rg.png" /><figcaption>getMovies getGenres query result</figcaption></figure><p>Ok, for now, it’s enough about querying and fetching. It would be great to know how to create or update some data. In GraphQL, there is no difference in syntax between creating, updating, or deleting data. For that, we use mutations. It’s really easy to remember. When we fetch data, we use queries. Otherwise, we always use the mutation. So the procedure is the same. Firstly you have to add a mutation to the schema definition(create an interface for that action), then provide the implementation inside the resolver object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f118beef0484ef25f6c82518e42081c/href">https://medium.com/media/4f118beef0484ef25f6c82518e42081c/href</a></iframe><p>All resolver functions are called by the apollo server when it needs to find some data. For example, suppose the client is trying to create a new movie — it will call the createmovie resolver function. All resolvers functions may take four input arguments, and so does the createMoviemutation function. Currently, I am interested only in the second one, which is input. So let’s omit the rest of them. Instead, I will discuss them deeply in another tutorial. <br>My resolver function generates the id for the next movie and pushes it to the movies array. In the end, it returns a new movie to the user. Having the schema and resolver updated, you are ready to test it out. First, let’s try this mutation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d5cf27c4de3ee2e62699ff62cc20da0/href">https://medium.com/media/7d5cf27c4de3ee2e62699ff62cc20da0/href</a></iframe><p>As you can see, it is super similar to the query you did before, although there are some differences. Most of all, you had to use the mutation keyword instead of the query. Then there are variables with `$` sign there. They are input variables — here, you describe what the new movie will look like. You can fill them in the section below the code editor. After executing CreateMoviemutation, you should see a result similar to mine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7bQbaVzN02jBU0P08ydNQ.png" /><figcaption>createMovie mutation result</figcaption></figure><p>So that’s all for today’s lesson. You have learned how to create a simple GraphQL schema, create resolver functions, and glue it together. That’s a great step forward to fully understanding GraphQL APIs. Next time, I’ll be talking about more advanced schema types, so I encourage you to stay in touch. See you next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5eb10240d38" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/introduction-to-graphql-for-nodejs-developers-5eb10240d38">Introduction to GraphQL for NodeJS Developers, pt. 1</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>