<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rossano D'Angelo</title>
    <description>The latest articles on Forem by Rossano D'Angelo (@rossanodan).</description>
    <link>https://forem.com/rossanodan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F106951%2Fdbab868d-0275-4837-a567-5e4add2a55d8.jpeg</url>
      <title>Forem: Rossano D'Angelo</title>
      <link>https://forem.com/rossanodan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rossanodan"/>
    <language>en</language>
    <item>
      <title>CAP Theorem: Consistency, Availability, Partition tolerance</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Wed, 30 Nov 2022 22:12:00 +0000</pubDate>
      <link>https://forem.com/rossanodan/cap-theorem-consistency-availability-partition-tolerance-1f8k</link>
      <guid>https://forem.com/rossanodan/cap-theorem-consistency-availability-partition-tolerance-1f8k</guid>
      <description>&lt;p&gt;This theorem states that it is impossible for a distributed system to simultaneously provide more than two of these three guarantees:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: all clients see the same data at the same time no matter which "node" of the system they connect to&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Availability&lt;/strong&gt;: any client which requests data gets a response even if some of the "nodes" of the system are not available&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Partition tolerance&lt;/strong&gt;: the system continues to operate despite network partitions&lt;sup id="fnref1"&gt;1&lt;/sup&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8myqpep523ji4f9zpdh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8myqpep523ji4f9zpdh.png" alt="CAP Theorem explained"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Ideal situation
&lt;/h2&gt;

&lt;p&gt;In an ideal world, network partition never occurs&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdhvc3glacqtkcr0nav6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdhvc3glacqtkcr0nav6.png" alt="CAP Theorem Ideal World"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Real world distributed system
&lt;/h2&gt;

&lt;p&gt;In a distributed system, data is usually replicated multiple times because partitions cannot be avoided.&lt;br&gt;
In the example below, node &lt;code&gt;n3&lt;/code&gt; becomes unavailable and cannot communicate with nodes &lt;code&gt;n1&lt;/code&gt; or &lt;code&gt;n2&lt;/code&gt;. Also data cannot be propagated to &lt;code&gt;n3&lt;/code&gt; from &lt;code&gt;n1&lt;/code&gt; or &lt;code&gt;n2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyjrdogdnajqlhn6db2pe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyjrdogdnajqlhn6db2pe.png" alt="CAP Theorem Real world"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we choose &lt;strong&gt;consistency over availability (CP system)&lt;/strong&gt; we must block all write operations to nodes &lt;code&gt;n1&lt;/code&gt; and &lt;code&gt;n2&lt;/code&gt; to avoid data inconsistency among these three nodes, and this makes the system unavailable.&lt;/p&gt;

&lt;p&gt;However, if we choose &lt;strong&gt;availability over consistency (AP system)&lt;/strong&gt; the system remains available and accepts read operations, even though it might return stale data. For write operations, nodes &lt;code&gt;n1&lt;/code&gt; and &lt;code&gt;n2&lt;/code&gt; will keep accepting them and data will be synced to node &lt;code&gt;n3&lt;/code&gt; when the network partition is resolved.&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;a partition indicates a communication break between two "nodes" ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Functional requirements vs Non-functional requirements</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Fri, 25 Nov 2022 16:30:00 +0000</pubDate>
      <link>https://forem.com/rossanodan/functional-requirements-vs-non-functional-requirements-5b07</link>
      <guid>https://forem.com/rossanodan/functional-requirements-vs-non-functional-requirements-5b07</guid>
      <description>&lt;p&gt;In order to build a good software system it's usually recommended a good understanding of its requirements. These requirements can be divided into two groups: &lt;strong&gt;functional requirements&lt;/strong&gt; and &lt;strong&gt;non-functional requirements&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functional requirements
&lt;/h2&gt;

&lt;p&gt;Functional requirements describe &lt;em&gt;how the product must behave&lt;/em&gt;. For example: &lt;em&gt;"the system sends a confirmation email when a new user account is created"&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Non-functional requirements
&lt;/h2&gt;

&lt;p&gt;Non-functional requirements specify the quality attributes of the system, that's why they are also called &lt;em&gt;quality attributes&lt;/em&gt;. The key types of non-functional requirements are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;performance and scalability&lt;/strong&gt; - How fast does the system return results? How much will this performance change with higher workloads?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;portability and compatibility&lt;/strong&gt; - Which hardware, operating systems, and browsers, along with their versions does the software run on? Does it conflict with other applications and processes within these environments?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;reliability, maintainability, availability&lt;/strong&gt; - How often does the system experience critical failures? How much time does it take to fix the issue when it arises? And how is user availability time compared to downtime?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;security&lt;/strong&gt; - How well are the system and its data protected against attacks?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These requirements are part of a format that is called SRS a.k.a. Software Requirement Specification.&lt;/p&gt;

</description>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Implementing optimistic UI with Apollo and ReactJS</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Wed, 13 Apr 2022 07:55:46 +0000</pubDate>
      <link>https://forem.com/rossanodan/implementing-optimistic-ui-with-apollo-and-reactjs-49ef</link>
      <guid>https://forem.com/rossanodan/implementing-optimistic-ui-with-apollo-and-reactjs-49ef</guid>
      <description>&lt;p&gt;Optimistic UI is a pattern that you can use to simulate the results of a mutation and update the UI even before receiving a response from the server. Once the response is received from the server, the optimistic result is thrown away and replaced with the actual result.&lt;/p&gt;

&lt;p&gt;This is the definition that Apollo gave to the term "optmistic user interface" on their &lt;a href="https://www.apollographql.com/docs/react/v2/performance/optimistic-ui/"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I recently discovered this concept by attending a course about improving performances of Apollo Client by using caching.&lt;/p&gt;

&lt;p&gt;But what kind of benefits does it bring? Does it come without downsides?&lt;/p&gt;

&lt;h2&gt;
  
  
  Apollo Client without Optimistic UI
&lt;/h2&gt;

&lt;p&gt;Here's a visual example of what happens when we use Apollo Client without the optimistic UI pattern when the user wants to send data to our application (for example, toggling on/off a favourite contact in a cloud based address book).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sTMpVJdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcsiupqsu83kody2f5dy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sTMpVJdP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcsiupqsu83kody2f5dy.png" alt="Without Optimistic UI" width="513" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This means that the user sees the UI updated only after the server computes the mutation and provides the results. If the datasource experiences delays, the user of our application will have to wait to see the result of his action.&lt;/p&gt;

&lt;p&gt;Here's a visual example of what happens when we use Apollo Client without the optimistic UI pattern.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IT9Vi_yX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s74q7xwps4f24c0rcq5p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IT9Vi_yX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s74q7xwps4f24c0rcq5p.png" alt="With Optimistic UI" width="508" height="471"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The user sees the UI updating right after the action without waiting for the server to compute the mutation. Apollo Client updates the caches providing an optimistic result: this means that we &lt;strong&gt;assume&lt;/strong&gt; that the result of the mutation is positive and update the UI accordingly.&lt;/p&gt;

&lt;p&gt;But what happens if, for any reason, the actual result of the mutation is different than the optimistic result provided? If the request fails, &lt;strong&gt;we need to rollback to the previous state&lt;/strong&gt; because otherwise the user would remain in a non-consistent state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Here you can observe the delay between the HTTP call and the UI to be updated. That's a classic effect of the Apollo Cache being updated after receiving the data from the data source.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yHKJC83P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84h5qtbjpi1w1gb862g2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yHKJC83P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84h5qtbjpi1w1gb862g2.gif" alt="Example without Optimistic UI" width="880" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's see how this changes applying the optimistic UI pattern - &lt;a href="https://www.apollographql.com/docs/react/v2/performance/optimistic-ui/"&gt;which is very easy to do with Apollo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yRaE3nkC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcr9qs5k68en1c4ylc4t.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yRaE3nkC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcr9qs5k68en1c4ylc4t.gif" alt="Example with Optimistic UI" width="880" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can notice how the UI updates right after the click and there isn't any "loading time". In the example above, the communication client cache - server is fast because both are running on my machine. But imagine if the server is hosted somewhere else and there are delays.. The optimistic response "anticipate" the response the server will give you to make the user experience smoother to the user.&lt;/p&gt;

</description>
      <category>apollo</category>
      <category>react</category>
      <category>performances</category>
    </item>
    <item>
      <title>Theming with styled-components ThemeProvider</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Sat, 10 Apr 2021 15:00:00 +0000</pubDate>
      <link>https://forem.com/rossanodan/theming-with-styled-components-themeprovider-37lc</link>
      <guid>https://forem.com/rossanodan/theming-with-styled-components-themeprovider-37lc</guid>
      <description>&lt;p&gt;If you are here probably you already know what &lt;code&gt;styled-components&lt;/code&gt; is so let’s skip the small talk.&lt;/p&gt;

&lt;p&gt;Prerequisites for this post is having a React-based application. If you have it, proceed reading. If you don’t, &lt;a href="https://github.com/facebook/create-react-app"&gt;take a look at this&lt;/a&gt; before proceeding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing styled-components
&lt;/h2&gt;

&lt;p&gt;Run the following command to install the npm package (or use &lt;code&gt;yarn&lt;/code&gt;, as you wish)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install styled-components
or
yarn add styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating Theme.js component with ThemeProvider
&lt;/h2&gt;

&lt;p&gt;Now, create &lt;code&gt;Theme.js&lt;/code&gt; file. This file will be your application’s theme entry point.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ThemeProvider } from 'styled-components';

const theme = {};

const Theme = ({ children }) =&amp;gt; {
  return &amp;lt;ThemeProvider theme={theme}&amp;gt;{children}&amp;lt;/ThemeProvider&amp;gt;;
};

export default Theme;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;theme&lt;/code&gt; object is where you’re going to define your theme variables like colours, font sizes and so on. As far as I know there isn’t a perfect way to define this object so it’s up to you to find &lt;em&gt;your perfect&lt;/em&gt; way to do so.&lt;/p&gt;

&lt;p&gt;I’ll give you an example below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const theme = {
  colour: {
    primary: '#3D315B',
    secondary: '#444B6E',
    background: '#708B75',
    link: '#9AB87A',
  },
  font: {
    size: {
      extraSmall: '14px',
      small: '16px',
      medium: '18px',
      large: '20px',
      extraLarge: '24px',
    },
    family: 'sans-serif',
  },
  breakpoint: {
    mobile: '375px',
    tablet: '600px',
    laptop: '1200px',
    desktop: '1600px',
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now your &lt;code&gt;Theme.js&lt;/code&gt; file should be something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ThemeProvider } from 'styled-components';

const theme = {
  colour: {
    primary: '#3D315B',
    secondary: '#444B6E',
    background: '#708B75',
    link: '#9AB87A',
  },
  font: {
    size: {
      extraSmall: '14px',
      small: '16px',
      medium: '18px',
      large: '20px',
      extraLarge: '24px',
    },
    family: 'sans-serif',
  },
  breakpoint: {
    mobile: '375px',
    tablet: '600px',
    laptop: '1200px',
    desktop: '1600px',
  },
};

const Theme = ({ children }) =&amp;gt; {
  return &amp;lt;ThemeProvider theme={theme}&amp;gt;{children}&amp;lt;/ThemeProvider&amp;gt;;
};

export default Theme;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Theme.js
&lt;/h2&gt;

&lt;p&gt;Now that your &lt;code&gt;Theme.js&lt;/code&gt; component is ready, you can wrap your React app with it. Go to your React entry point and wrap everything with &lt;code&gt;&amp;lt;Theme&amp;gt;...&amp;lt;/Theme&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom';

import Theme from './Theme';

ReactDOM.render(
  &amp;lt;Theme&amp;gt;
    &amp;lt;header&amp;gt;&amp;lt;/header&amp;gt;
    &amp;lt;main&amp;gt;
      &amp;lt;p&amp;gt;Hello, there!&amp;lt;/p&amp;gt;
    &amp;lt;/main&amp;gt;
    &amp;lt;footer&amp;gt;&amp;lt;/footer&amp;gt;
  &amp;lt;/Theme&amp;gt;,
  document.getElementById('root')
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great, now you need a &lt;code&gt;styled component&lt;/code&gt; to see &lt;code&gt;ThemeProvider&lt;/code&gt; in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// import styled-components
import styled, { css } from 'styled-components';

// create Text component
const Text = styled.p`
  ${({ theme }) =&amp;gt; css`
    color: ${theme.colour.primary};
    font-family: ${theme.font.family};
    font-size: ${theme.font.size.medium};
  `}
`;

// use Text component created above
&amp;lt;main&amp;gt;
  &amp;lt;Text&amp;gt;Hello, there!&amp;lt;/Text&amp;gt;
&amp;lt;/main&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, wrapping the whole application with &lt;code&gt;ThemeProvider&lt;/code&gt;, the styled components receive &lt;code&gt;theme&lt;/code&gt; in the &lt;code&gt;props&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And this is the result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.rossanodan.me/static/485c12f634c50460ffe9a27bb6d3cac5/29beb/Result.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e7SI7Yw7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.rossanodan.me/static/485c12f634c50460ffe9a27bb6d3cac5/fcda8/Result.png" alt="Result" title="Result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Powerful, eh? &lt;strong&gt;But there’s more&lt;/strong&gt;. You can work with media queries in the same way.&lt;/p&gt;

&lt;p&gt;Imagine that you want to change the style of &lt;code&gt;Text&lt;/code&gt; component only for mobile devices.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Text = styled.p`
  ${({ theme }) =&amp;gt; css`
    color: ${theme.colour.primary};
    font-family: ${theme.font.family};
    font-size: ${theme.font.size.medium};

    // media query
    @media (max-width: ${theme.breakpoint.mobile}) {
      font-size: ${theme.font.size.small};
      background-color: ${theme.colour.background};
    }
  `}
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is how it should look like for &lt;code&gt;376px&lt;/code&gt; and &lt;code&gt;375px&lt;/code&gt; respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.rossanodan.me/static/922a6be44f3b389b3128c04fdf0df0b1/769f8/MediaQuery376px.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cD6edQaN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.rossanodan.me/static/922a6be44f3b389b3128c04fdf0df0b1/fcda8/MediaQuery376px.png" alt="Text for resolution 376px" title="Text for resolution 376px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.rossanodan.me/static/c679f0ddcae49e00d6efac1f4b5699c5/769f8/MediaQuery375px.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l3RhZy1D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.rossanodan.me/static/c679f0ddcae49e00d6efac1f4b5699c5/fcda8/MediaQuery375px.png" alt="Text for resolution 375px" title="Text for resolution 375px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You made it! You now have a basic theming setup for your React app!&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s next?
&lt;/h2&gt;

&lt;p&gt;From this point it would make sense improving this theming setup to allow multiple themes like, for example, dark and light theme.&lt;/p&gt;

</description>
      <category>react</category>
      <category>styledcomponents</category>
    </item>
    <item>
      <title>How I monitor my blog</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Wed, 07 Apr 2021 22:00:00 +0000</pubDate>
      <link>https://forem.com/rossanodan/how-i-monitor-my-blog-iol</link>
      <guid>https://forem.com/rossanodan/how-i-monitor-my-blog-iol</guid>
      <description>&lt;h2&gt;
  
  
  What
&lt;/h2&gt;

&lt;p&gt;I use different monitoring and analytics tools to monitor my blog: &lt;a href="https://analytics.google.com/"&gt;Google Analytics&lt;/a&gt;, &lt;a href="https://vercel.com/analytics"&gt;Vercel Analytics&lt;/a&gt; and &lt;a href="https://one.eu.newrelic.com/"&gt;New Relic&lt;/a&gt;. Maybe is too much, given that my blog doesn’t have a lot of traffic and it’s not a “critical system” to be continuously monitored and kept online (if it goes down for a couple of minutes no one will complain!). But since these services are free to use and since I use New Relic at work, I decided to use it for my blog and maybe to learn more about it.&lt;/p&gt;

&lt;p&gt;But.. &lt;strong&gt;what is New Relic&lt;/strong&gt;? Well, this is what I understood so far: New Relic is a &lt;strong&gt;monitoring tool that provides real-time data, usage analytics and allows you to monitor your services and to set alarms&lt;/strong&gt; for them (imagine you want to receive a notification when one of your services goes down to be able to promptly respond to the failures). If you want a more specific definition of it, visit the &lt;a href="https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/get-started/introduction-new-relic/"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I don’t monitor any service for my blog - I don’t have any! - but only the front end performances. And I do so with &lt;a href="https://docs.newrelic.com/docs/new-relic-one/use-new-relic-one/get-started/introduction-new-relic-one/"&gt;New Relic One&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;I do monitor my blog because I want to understand its performances and what I can do to improve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How
&lt;/h2&gt;

&lt;p&gt;My blog is built with GatsbyJS so I used the plugin &lt;a href="https://dev.togatsby-plugin-newrelic"&gt;gatsby-plugin-newrelic&lt;/a&gt;. I won’t write here what I did to set up New Relic because there’s nothing their &lt;a href="https://github.com/newrelic/gatsby-plugin-newrelic/blob/main/README.md"&gt;README&lt;/a&gt; doesn’t say. And it explains how to do it so well!&lt;/p&gt;

&lt;p&gt;What I can add is that I monitor only my production environment. Here’s &lt;a href="https://github.com/rossanodan/rossanodan/blob/master/gatsby-config.js#L163"&gt;my configuration&lt;/a&gt; to monitor production.&lt;/p&gt;

&lt;p&gt;Here you can see a part of my dashboard where I see data coming through.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.rossanodan.me/static/8aa5cb6929e2a0ecaa34209866b00b1b/b7756/Dashboard-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4oZls-BB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.rossanodan.me/static/8aa5cb6929e2a0ecaa34209866b00b1b/fcda8/Dashboard-1.png" alt="The dashboard" title="The dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see my blog’s &lt;strong&gt;FID&lt;/strong&gt; , First Input Delay.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To put it in simpler terms, the FID is the delay between when you click or tap on something like a link or a button, and the time that the browser responds to your action and starts processing it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://www.rossanodan.me/static/2c4431ff0218e94bfc05d47ad9826544/b7756/Dashboard-2.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4jUMrim7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.rossanodan.me/static/2c4431ff0218e94bfc05d47ad9826544/fcda8/Dashboard-2.png" alt="How long my blog takes to load by URL" title="How long my blog takes to load by URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want to be honest: I can’t understand all of these charts yet. But that’s why I choose to monitor my blog with New Relic: I want to learn and become more familiar with it.&lt;/p&gt;

&lt;p&gt;So don’t blame me if I’m not saying anything really interesting in this article. More interesting stuff will come, with time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I started monitoring my blog a few days ago so, for now, there’s not so much I can say but New Relic looks good and very easy to use. It offers a lot of charts, analytics and alerts… Which I didn’t try yet!!&lt;/p&gt;

&lt;p&gt;If you are searching for a good monitoring tool for your application, New Relic is what you need.&lt;/p&gt;

</description>
      <category>newrelic</category>
      <category>monitoring</category>
      <category>analytics</category>
    </item>
    <item>
      <title>What I like the most about styled-components</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Sun, 04 Apr 2021 21:00:00 +0000</pubDate>
      <link>https://forem.com/rossanodan/what-i-like-the-most-about-styled-components-cdp</link>
      <guid>https://forem.com/rossanodan/what-i-like-the-most-about-styled-components-cdp</guid>
      <description>&lt;p&gt;When I started writing my first lines of React code, the first thing I did was setting up &lt;em&gt;Sass&lt;/em&gt; and &lt;em&gt;CSS modules&lt;/em&gt; because I liked working with well-structured stylesheets. Variables to define themes, files divided into groups - header, body, footer, etc. I remember it was so great renaming files from &lt;em&gt;App.css&lt;/em&gt; to &lt;em&gt;App.module.scss&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;But like all the best things in this doomed world, there was an end. And the end of all that beauty happened when I discovered &lt;a href="https://styled-components.com/"&gt;styled-components&lt;/a&gt;. Something far more beautiful than &lt;em&gt;CSS modules&lt;/em&gt;, believe me.&lt;/p&gt;

&lt;p&gt;I state that I never used &lt;em&gt;PostCSS&lt;/em&gt; or &lt;em&gt;CSS in JS&lt;/em&gt; so maybe I lost great things on the way. But I have no regrets because probably I’d ended up on &lt;em&gt;styled-components&lt;/em&gt; anyway.&lt;/p&gt;

&lt;p&gt;I won’t list here all the advantages that &lt;em&gt;styled-components&lt;/em&gt; brings to the table but only what I think it’s worth mentioning. For the rest, &lt;a href="https://styled-components.com/docs"&gt;check out the official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unique class names
&lt;/h3&gt;

&lt;p&gt;You can have two or more components with the same name until they are in different files. See the example below in which I have two styled components &lt;em&gt;Container&lt;/em&gt; and I use them in different files. The clash won’t happen because &lt;em&gt;styled-components&lt;/em&gt; will create a hash for each of them, something like &lt;code&gt;Appstyles __Container-qk6y7u-9&lt;/code&gt; and &lt;code&gt;Profilestyles__ Container-awrt4d-2&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js
import React from 'react';

import { Container, Text } from './App.styles.js';

const App = () =&amp;gt; {
  &amp;lt;Container&amp;gt;
    ...
    &amp;lt;Text&amp;gt;Hello, there!&amp;lt;/Text&amp;gt;
  &amp;lt;/Container&amp;gt;;
};

export default App;

// Profile.js
import React from 'react';

import { Container } from './Profile.styles.js';

const Profile = () =&amp;gt; {
  &amp;lt;Container&amp;gt;...&amp;lt;/Container&amp;gt;;
};

export default Profile;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Passing &lt;em&gt;props&lt;/em&gt; to components
&lt;/h3&gt;

&lt;p&gt;In the example below you can see how I can easily change the &lt;em&gt;background-color&lt;/em&gt; of the &lt;em&gt;Container&lt;/em&gt; depending on a variable defined in the JavaScript code. This is a very powerful feature.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js
import React from 'react';

import { Container } from './App.styles.js';

const App = () =&amp;gt; {
  &amp;lt;Container isError={true}&amp;gt;
    ...
    &amp;lt;p&amp;gt;Hello, there!&amp;lt;/p&amp;gt;
  &amp;lt;/Container&amp;gt;;
};

export default App;

// App.styles.js
import styled, { css } from 'styled-components';

export const Container = styled.div`
  ${({ isError }) =&amp;gt;
    isError
      ? css`
          background-color: red;
        `
      : css`
          background-color: white;
        `}
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Styling inheritance
&lt;/h3&gt;

&lt;p&gt;You’ll be able to create styled components which inherit the style from another component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.styles.js
import styled from 'styled-components';

export const Text = styled.p`
  font-family: sans-serif;
  font-size: 16px;
`;

export const ErrorText = styled(Text)`
  color: red;
`;

export const SuccessText = styled(Text)`
  color: green;
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Theming
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;syled-components&lt;/em&gt; allows you to easily work with different themes in you application. It provides you with a &lt;em&gt;ThemeProvider&lt;/em&gt; ot be used as you can see below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js
import React from 'react';
import { ThemeProvider } from 'styled-components';

const theme = {
  colors: {
    lightBlue: "#AFDBD2",
  },
  ...
}

const App = () =&amp;gt; (
  &amp;lt;ThemeProvider theme={theme}&amp;gt;
    &amp;lt;Container&amp;gt;
      ...
    &amp;lt;/Container&amp;gt;
  &amp;lt;/ThemeProvider&amp;gt;
);

export default App;

// App.styles.js
import React from 'react';
import styled from 'styled-components';

export const Container = styled.div`
  ...
  background-color: ${props =&amp;gt; props.theme.colors.lightBlue};
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also create a &lt;em&gt;Theme.js&lt;/em&gt; component, as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Theme.js
import React from 'react';
import { ThemeProvider } from 'styled-components';

const theme = {
  colors: {
    lightBlue: "#AFDBD2",
  },
  ...
}

const Theme = ({ children }) =&amp;gt; (
  &amp;lt;ThemeProvider theme={theme}&amp;gt;
    {children}
  &amp;lt;/ThemeProvider&amp;gt;
);

export default Theme;

// App.js
import React from 'react';
import Theme from './Theme';

const App = () =&amp;gt; (
  &amp;lt;Theme&amp;gt;
    &amp;lt;Container&amp;gt;...&amp;lt;/Container&amp;gt;
  &amp;lt;/Theme&amp;gt;
);

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;App.styles.js&lt;/em&gt; doesn’t change.&lt;/p&gt;

&lt;p&gt;And it’s not over!! You can also use &lt;code&gt;higher-order components&lt;/code&gt; and &lt;code&gt;React hooks&lt;/code&gt; to get the theme style.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { withTheme } from 'styled-components';

class App extends React.Component {
  ...
  render () {
    ... // this.props.theme is available here
  }
}

export default withTheme(App);

import React, { useContext } from 'react';
import { ThemeContext } from 'styled-components';

const App = () =&amp;gt; {
  const themeContext = useContext(ThemeContext);

  return (
    ...
  );
}

export default withTheme(App);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I said, these are the things I personally found amazing about styled-components working with it everyday. I’m sure there are more that you may find interesting for your projects.&lt;/p&gt;

&lt;p&gt;So.. what do you think? Worth taking a look?&lt;/p&gt;

</description>
      <category>react</category>
      <category>styledcomponents</category>
    </item>
    <item>
      <title>I finally created my personal blog</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Thu, 01 Apr 2021 08:19:38 +0000</pubDate>
      <link>https://forem.com/rossanodan/i-finally-created-my-personal-blog-3doe</link>
      <guid>https://forem.com/rossanodan/i-finally-created-my-personal-blog-3doe</guid>
      <description>&lt;p&gt;I finally created my personal blog.&lt;/p&gt;

&lt;p&gt;I needed something more flexible than dev.to because it didn't feel right posting whatever I wanted here. And also I wanted something made by myself, something that I can change if I want.&lt;/p&gt;

&lt;p&gt;So that I created &lt;a href="https://www.rossanodan.me/"&gt;www.rossanodan.me&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Technical details: I used Gatsby to create it. It's been funny because it's very customisable if you know where to put your hands to the code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's still pretty empty, I know, but it won't be forever. I promised myself I will add content constantly.&lt;/p&gt;

&lt;p&gt;This looks like a goodbye to dev.to but it isn't. I will continue use it, maybe more as reader than as a write but here I am.&lt;/p&gt;

&lt;p&gt;Let me know what you think about my new blog. I'm open to suggestions!!&lt;/p&gt;

</description>
      <category>blog</category>
      <category>general</category>
    </item>
    <item>
      <title>Useful resources to learn more about Agile and Scrum</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Thu, 25 Mar 2021 22:00:00 +0000</pubDate>
      <link>https://forem.com/rossanodan/useful-resources-to-learn-more-about-agile-and-scrum-3c3g</link>
      <guid>https://forem.com/rossanodan/useful-resources-to-learn-more-about-agile-and-scrum-3c3g</guid>
      <description>&lt;p&gt;If you work into software development - if you don’t, I have no idea how you ended up here - and especially in medium/big sized companies, you surely heard about &lt;strong&gt;Agile&lt;/strong&gt; and &lt;strong&gt;Scrum&lt;/strong&gt;. So probably you don’t need what follows.&lt;/p&gt;

&lt;p&gt;For all the others instead, here’s a list of useful links where you can read about Agile, Scrum, Scrum roles and sprint ceremonies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.atlassian.com/agile"&gt;https://www.atlassian.com/agile&lt;/a&gt; - if you don’t know what Agile is, please read this first&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.atlassian.com/agile/scrum"&gt;https://www.atlassian.com/agile/scrum&lt;/a&gt; - Scrum framework. Here you can learn all about Scrum (sprints, agile ceremonies, standup, roles, etc)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://agilemanifesto.org/principles.html"&gt;https://agilemanifesto.org/principles.html&lt;/a&gt; - twelve general principles of the Agile Manifesto&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=9TycLR0TqFA"&gt;https://www.youtube.com/watch?v=9TycLR0TqFA&lt;/a&gt; - Short but very useful video about Scrum&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can thank me later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/kmQREsvNQrhrHdkN7G/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/kmQREsvNQrhrHdkN7G/giphy.gif" alt="You're welcome"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>agile</category>
      <category>scrum</category>
    </item>
    <item>
      <title>What are your favourite podcasts?</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Wed, 17 Feb 2021 00:32:49 +0000</pubDate>
      <link>https://forem.com/rossanodan/what-are-your-favourite-podcasts-odk</link>
      <guid>https://forem.com/rossanodan/what-are-your-favourite-podcasts-odk</guid>
      <description>&lt;p&gt;At the moment I'm listening to &lt;strong&gt;Demoni Urbani&lt;/strong&gt;, an Italian (Italian is my native language) podcast which tells about some of the worse crime episodes really happened in Italy. It intrigues me. It's available on &lt;a href="https://podcasts.apple.com/gb/podcast/demoni-urbani/id1409782375"&gt;Apple Podcasts&lt;/a&gt; and on &lt;a href="https://open.spotify.com/show/36dX67Whak48QfCISNOQyO"&gt;Spotify&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="100%" height="232px" src="https://open.spotify.com/embed/show/36dX67Whak48QfCISNOQyO"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Recently I discovered &lt;strong&gt;The Joe Rogan Experience&lt;/strong&gt; podcast. It sounds interesting!! I started listening the episode with Elon Musk. It's amazing listening about all the stuff about space and Mars colonisation directly from him - who, I suspect, has to know a lot about it! This show is available on &lt;a href="https://open.spotify.com/show/4rOoJ6Egrf8K2IrywzwOMk"&gt;Spotify&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="100%" height="232px" src="https://open.spotify.com/embed/episode/2aB2swgyXqbFA06AxPlFmr"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;And what about you? What are your favourite podcasts? Anything to share? True Crime, Tech, Actuality.. I'm ready to listen! 🎧 Preferred languages: English 🇬🇧 and/or Italian 🇮🇹.&lt;/p&gt;

</description>
      <category>podcast</category>
    </item>
    <item>
      <title>How to create a GraphQL server with ExpressJS and Apollo Server</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Sun, 31 Jan 2021 21:15:57 +0000</pubDate>
      <link>https://forem.com/rossanodan/how-to-create-a-graphql-server-with-expressjs-and-apollo-server-1h13</link>
      <guid>https://forem.com/rossanodan/how-to-create-a-graphql-server-with-expressjs-and-apollo-server-1h13</guid>
      <description>&lt;p&gt;In this article, I'm going to show how to create a GraphQL Server using ExpressJS and Apollo Server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crete the project folder and install Apollo Server and Express
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir graphql-server-playground
cd graphql-server-playground
npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;package.json&lt;/code&gt; file should be something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "graphql-server-playground",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add description, keywords and author if you want.&lt;/p&gt;

&lt;p&gt;In order to setup Express and Apollo Server, install the following dev dependencies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/@babel/cli"&gt;@babel/cli&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/@babel/core"&gt;@babel/core&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/@babel/node"&gt;@babel/node&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/@babel/preset-env"&gt;@babel/preset-env&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/nodemon"&gt;nodemon&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @babel/cli @babel/core @babel/node @babel/preset-env nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the following dependencies&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/apollo-server-express"&gt;apollo-server-express&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/express"&gt;express&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/graphql"&gt;graphql&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;graphql-import&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/graphql-tools"&gt;graphql-tools&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install apollo-server-express express graphql graphql-import graphql-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, in the root folder of your project, create the &lt;code&gt;src&lt;/code&gt; folder and the &lt;code&gt;index.js&lt;/code&gt; file in it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import { ApolloServer, gql } from 'apollo-server-express';

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () =&amp;gt; 'Hello world!',
  },
};

const server = new ApolloServer({ typeDefs, resolvers });

const app = express();
server.applyMiddleware({ app });

app.listen({ port: 4001 }, () =&amp;gt;
  console.log(`🚀 Server ready at http://localhost:4001${server.graphqlPath}`)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the &lt;code&gt;package.json&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  ...
  "main": "src/index.js",
  "scripts": {
    "start": "nodemon --exec babel-node -- ./src/index.js"
  },
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Nodemon&lt;/code&gt; is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before running the server, we have to create a &lt;code&gt;.babelrc&lt;/code&gt; file in the root folder of the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "presets": ["@babel/preset-env"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file tells NodeJS we are using Babel 7 and that the code has to be transpiled for the browser.&lt;/p&gt;

&lt;p&gt;Now start the server with &lt;code&gt;npm start&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start

&amp;gt; graphql-server-playground@1.0.0 start graphql-server-playground
&amp;gt; nodemon --exec babel-node -- ./src/index.js

[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node ./src/index.js`
🚀 Server ready at http://localhost:4001/graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The GraphQL server is now running on your machine at &lt;a href="http://localhost:4001/graphql"&gt;http://localhost:4001/graphql&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Playground
&lt;/h2&gt;

&lt;p&gt;The Playground is where you can run your queries and check for the documentation or your schema.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IF_0wzzH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v4oel3e6ktdqjhqcddtk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IF_0wzzH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v4oel3e6ktdqjhqcddtk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sUcXque6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jngyudduytchldjgn568.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sUcXque6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jngyudduytchldjgn568.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DrHNIVdR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a6kevl7s8rsizrcny6t3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DrHNIVdR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a6kevl7s8rsizrcny6t3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only query available now is the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  hello
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you can see in the code, it corresponds to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const typeDefs = gql`
  type Query {
    hello: String
  }
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each query has to have a &lt;code&gt;resolver&lt;/code&gt;. The resolver is a function that defines what the query returns&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const resolvers = {
  Query: {
    hello: () =&amp;gt; 'Hello world!',
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the resolver for the &lt;code&gt;hello&lt;/code&gt; query returns a string, &lt;code&gt;Hello world!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you want to learn more about GraphQL queries and resolvers, take a look &lt;a href="https://www.apollographql.com/docs/tutorial/resolvers/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining the schema
&lt;/h2&gt;

&lt;p&gt;Before defining the schema, we have to decide what kind of data this server will provide to the client.&lt;/p&gt;

&lt;p&gt;Let's say we want to store and serve information about our address book. So the data I exptect to have is a list of people whith names, phone numbers and email addresses. Since we don't have a real database for now, let's mock it in the &lt;code&gt;index.js&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
const persons = [
    {
        id: 1,
        name: "Ash Ketchum",
        phone_number: "+440000000000",
        email: "ash@gmail.com",
    },
    {
        id: 2,
        name: "Professor Oak",
        phone_number: "+441111111111",
        email: "proak@gmail.com",
    },
    {
        id: 3,
        name: "Gary Oak",
        phone_number: "+442222222222",
    },
];
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will be our temporary database.&lt;/p&gt;

&lt;p&gt;Now the schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const typeDefs = gql`
  type Person {
      id: Int!
      name: String!
      email: String
  }
  type Query {
    person(id: Int!): Person
  }
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's have a closer look.&lt;/p&gt;

&lt;p&gt;Since we already defined the structure of the data, we are pretty sure that what we will receive from the database will have this shape:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;id: Int! (an integer, non nullable)&lt;/li&gt;
&lt;li&gt;name: String! (a string, non nullable)&lt;/li&gt;
&lt;li&gt;email: String (a string, nullable)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The query &lt;code&gt;person(id: Int!): Person&lt;/code&gt; wants an id as parameter (note the id is non nullable - it can't be null or we won't be able to retrieve anything!) and it returns a &lt;code&gt;Person&lt;/code&gt; (an object defined by the Person type). Since it may happen the person we search for is not present in the database, the return type of this query is nullable (it can returns &lt;code&gt;null&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Let's run the query in the Playground&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  person(id: 1) {
    id
    name
    email
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g5QnQjFE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/21x8tes80fdn39e4bzo5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g5QnQjFE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/21x8tes80fdn39e4bzo5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing a new query
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const typeDefs = gql`
  ...
  type Query {
    ...
    persons: [Person]!
  }
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const resolvers = {
  Query: {
    ...
    persons: (_, __, ___) =&amp;gt; persons,
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty straight-forward, right? The new query &lt;code&gt;persons&lt;/code&gt; returns the whole &lt;code&gt;persons&lt;/code&gt; array. Let's run the new query on the Playground&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qt3Rr2_u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oi6mosout7cpf13789y8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qt3Rr2_u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oi6mosout7cpf13789y8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing a mutation
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;Mutation&lt;/code&gt; is a function used to create, update and delete data in GraphQL. If you think at &lt;strong&gt;CRUD&lt;/strong&gt;, mutations represent the C(reate) U(update) D(elete).&lt;/p&gt;

&lt;p&gt;Let's create a new type &lt;code&gt;PersonInput&lt;/code&gt; and another root type &lt;code&gt;Mutation&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const typeDefs = gql`
  ...
  input PersonInput {
    id: Int!
    name: String!
    email: String
  }
  type Mutation {
    createPerson(person: PersonInput!): Person
  }
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function &lt;code&gt;createPerson&lt;/code&gt; accepts a non nullable object of type &lt;code&gt;PersonInput&lt;/code&gt; and returns another object of type &lt;code&gt;Person&lt;/code&gt;. It's just a case the two types &lt;code&gt;Person&lt;/code&gt; and &lt;code&gt;PersonInput&lt;/code&gt; are the same.&lt;/p&gt;

&lt;p&gt;The mutation then is something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const resolvers = {
  ...
  Mutation: {
    createPerson(_, { person }, __) =&amp;gt; {
      persons.push(person);
      return person;
    },
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For simplicity's sake we are entering manually the ID paying attention to not reuse the same ID twice (or the query &lt;code&gt;person&lt;/code&gt; will unexpectedly return two results!).&lt;/p&gt;

&lt;p&gt;Let's use the mutation on the Playground&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mutation {
  createPerson(person: {id: 5, name: "Brock", email: "brock@gmail.com"}) {
    id
    name
    email
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_VQAMs5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vzdvfjsmdo4lqfqxqrw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_VQAMs5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vzdvfjsmdo4lqfqxqrw6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also run the &lt;code&gt;persons&lt;/code&gt; query to see how the list of people is updated&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XPSfKBoD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uzrik9qur85oao6jymre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XPSfKBoD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uzrik9qur85oao6jymre.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please remember that we are using an object as temporary database and that you will lose the data you add/change/remove via mutations once you restart the server! If you want some persistency, think about &lt;a href="https://www.apollographql.com/blog/a-deep-dive-on-apollo-data-sources/"&gt;connecting the GraphQL server to a data source&lt;/a&gt;. I won't do that in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Improving the code style with Prettier
&lt;/h2&gt;

&lt;p&gt;Install Prettier with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install prettier --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update your &lt;code&gt;package.json&lt;/code&gt; file as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  ...
  "prettier": "prettier --write ."
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file &lt;code&gt;.prettierrc.json&lt;/code&gt; in the root folder of your project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": false,
  "singleQuote": true
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file contains the configuration of Prettier and the rules it will apply to your code.&lt;/p&gt;

&lt;p&gt;Create a second file, &lt;code&gt;.prettierignore&lt;/code&gt; and copy-paste the content of your &lt;code&gt;.gitignore&lt;/code&gt;. This file will simply tell Prettier which files to ignore while formatting the code.&lt;/p&gt;

&lt;p&gt;Now when you run &lt;code&gt;npm run prettier&lt;/code&gt; it will apply the formatting rules to all files in the root directory and sub-directories. You can change this replacing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"prettier": "prettier --write ."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"prettier": "prettier --write ./src/**"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case Prettier will format files in the &lt;code&gt;src&lt;/code&gt; folder and in its sub-folders.&lt;/p&gt;

&lt;h2&gt;
  
  
  It's a wrap
&lt;/h2&gt;

&lt;p&gt;That's it, you made it! Now you have a GraphQL server running locally and a very useful Playground to execute queries! 🚀&lt;/p&gt;

&lt;p&gt;Here's the repository with all the code we wrote in this article &lt;a href="https://github.com/rossanodan/graphql-server-playground"&gt;https://github.com/rossanodan/graphql-server-playground&lt;/a&gt;. Feel free to fork it and use it as your own or as a template.&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>express</category>
      <category>apolloserver</category>
      <category>prettier</category>
    </item>
    <item>
      <title>Apollo Server with Express, Babel 7 and ESLint</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Sat, 30 Jan 2021 20:54:37 +0000</pubDate>
      <link>https://forem.com/rossanodan/apollo-server-with-express-babel-7-and-eslint-1aci</link>
      <guid>https://forem.com/rossanodan/apollo-server-with-express-babel-7-and-eslint-1aci</guid>
      <description>&lt;p&gt;In this repository you can find a simple Apollo Server created with Express, Babel 7 and ESLint&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/rossanodan/cinematheque-apollo-server-playground"&gt;https://github.com/rossanodan/cinematheque-apollo-server-playground&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, it's a playground. This means that I will probably change the code day by day as I do practice with &lt;code&gt;GraphQL&lt;/code&gt; and &lt;code&gt;Apollo.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Feel free to fork this repository and to use it as your own to do practice with them.&lt;/p&gt;

&lt;p&gt;PS. To use this project you will need an API key for &lt;a href="https://developers.themoviedb.org/"&gt;The Movie Database&lt;/a&gt; which I used to fetch some data from.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.themoviedb.org/"&gt;Create an account&lt;/a&gt; and you will be provided of an API key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;List of useful resources I used to setup my plauground:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.codementor.io/@osazeedoosagie/easy-set-up-babel-7-for-nodejs-rg3zak6pj"&gt;setup Babel 7 for NodeJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/nodemon"&gt;install and setup Nodemon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eslint.org/docs/user-guide/getting-started"&gt;getting started with ESLint&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/devdammak/setting-up-eslint-in-your-javascript-project-with-vs-code-2amf"&gt;setup ESLint in your JavaScript project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/apollo-server-express"&gt;setting up Apollo Server with Express&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have fun! 😄&lt;/p&gt;

</description>
      <category>apollo</category>
      <category>graphql</category>
      <category>express</category>
      <category>eslint</category>
    </item>
    <item>
      <title>How to setup a minimal GraphQL server with Express and Apollo Server</title>
      <dc:creator>Rossano D'Angelo</dc:creator>
      <pubDate>Sat, 23 Jan 2021 18:35:49 +0000</pubDate>
      <link>https://forem.com/rossanodan/how-to-setup-a-minimal-graphql-server-with-express-and-apollo-server-2pao</link>
      <guid>https://forem.com/rossanodan/how-to-setup-a-minimal-graphql-server-with-express-and-apollo-server-2pao</guid>
      <description>&lt;p&gt;At the end of this article you will be able to create a minimal GraphQL from scratch using ExpressJS and Apollo Server.&lt;/p&gt;

&lt;p&gt;If you're reading this article I expect you to have a basic knowledge of ExpressJS, GraphQL and Apollo. If not, this article won't help you so much but you can still take a look to it if you're interested.&lt;/p&gt;

&lt;p&gt;To make up for it, I leave here some useful URLs where you can learn more about those topics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://expressjs.com/"&gt;https://expressjs.com/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://graphql.org/"&gt;https://graphql.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.apollographql.com/"&gt;https://www.apollographql.com/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up and dependencies installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir graphql-server-express
cd graphql-server-express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express apollo-server-express
npm install --save-dev @babel/core @babel/node @babel/preset-env babel-cli babel-preset-es2015 nodemon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Pretty straight-forward so far, right? Good.&lt;/p&gt;
&lt;h3&gt;
  
  
  Let's jump into the code
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;.babelrc&lt;/code&gt; file in the root folder&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "presets": ["@babel/preset-env"]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This file will enable us to use some ES6 capabilities such as the use of &lt;code&gt;import&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;src&lt;/code&gt; folder and the &lt;code&gt;index.js&lt;/code&gt; file in it as follows&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from "express";
import { ApolloServer, gql } from "apollo-server-express";

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () =&amp;gt; "Hello world!",
  },
};

const server = new ApolloServer({ typeDefs, resolvers });

const app = express();
server.applyMiddleware({ app });

app.listen({ port: 4001 }, () =&amp;gt;
  console.log(`Server listening on http://localhost:4001${server.graphqlPath}`)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A couple of things about this file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is the entry point of the server&lt;/li&gt;
&lt;li&gt;I use one file for all the code just for simplicity - you can decide to split it into multiple files&lt;/li&gt;
&lt;li&gt;I use the port &lt;code&gt;4001&lt;/code&gt; but you can use another port if you want&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  How to start the server with &lt;code&gt;nodemon&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Now update the &lt;code&gt;script&lt;/code&gt; command in the &lt;code&gt;package.json&lt;/code&gt; file as follows&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
  "scripts": {
    "start": "nodemon --exec babel-node src/index.js"
  }
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now run &lt;code&gt;npm start&lt;/code&gt; in the terminal. The GraphQL Playground will be available at &lt;code&gt;http://localhost:4001/graphql&lt;/code&gt; (or any other address/port you used).&lt;/p&gt;

&lt;p&gt;I published this little project on GitHub for future reference &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/rossanodan"&gt;
        rossanodan
      &lt;/a&gt; / &lt;a href="https://github.com/rossanodan/graphql-server-express"&gt;
        graphql-server-express
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A minimal GraphQL server developed with Express and Apollo Server
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h2&gt;
Setting up and dependencies installation&lt;/h2&gt;
&lt;div class="snippet-clipboard-content position-relative overflow-auto"&gt;&lt;pre&gt;&lt;code&gt;mkdir graphql-server-express
cd graphql-server-express
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="snippet-clipboard-content position-relative overflow-auto"&gt;&lt;pre&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="snippet-clipboard-content position-relative overflow-auto"&gt;&lt;pre&gt;&lt;code&gt;npm install express apollo-server-express
npm install --save-dev @babel/core @babel/node @babel/preset-env babel-cli babel-preset-es2015 nodemon
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Pretty straight-forward so far, right? Good.&lt;/p&gt;
&lt;h3&gt;
Let's jump into the code&lt;/h3&gt;
&lt;p&gt;Create a &lt;code&gt;.babelrc&lt;/code&gt; file in the root folder&lt;/p&gt;
&lt;div class="snippet-clipboard-content position-relative overflow-auto"&gt;&lt;pre&gt;&lt;code&gt;{
  "presets": ["@babel/preset-env"]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This file will enable us to use some ES6 capabilities such as the use of &lt;code&gt;import&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Create &lt;code&gt;src&lt;/code&gt; folder and the &lt;code&gt;index.js&lt;/code&gt; file in it as follows&lt;/p&gt;
&lt;div class="snippet-clipboard-content position-relative overflow-auto"&gt;&lt;pre&gt;&lt;code&gt;import express from "express";
import { ApolloServer, gql } from "apollo-server-express";

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () =&amp;gt; "Hello world!",
  },
};

const server = new ApolloServer({ typeDefs, resolvers });

const app = express();
server.applyMiddleware({ app });

app.listen({ port: 4001 }, () =&amp;gt;
  console.log(`Server listening on http://localhost:4001${server.graphqlPath}`)
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A couple of things about this file:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This is the entry point of…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/rossanodan/graphql-server-express"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



</description>
      <category>graphql</category>
      <category>apollo</category>
      <category>express</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
