<?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>DEV Community: Ryan Doyle</title>
    <description>The latest articles on DEV Community by Ryan Doyle (@doylecodes).</description>
    <link>https://dev.to/doylecodes</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%2F138063%2Ff7de534e-9cd6-412b-ab34-893e2c28ab58.jpeg</url>
      <title>DEV Community: Ryan Doyle</title>
      <link>https://dev.to/doylecodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/doylecodes"/>
    <language>en</language>
    <item>
      <title>Is Building Your Own Portfolio a Waste of Time?</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Sat, 13 Apr 2024 16:50:32 +0000</pubDate>
      <link>https://dev.to/doylecodes/is-building-your-own-portfolio-a-waste-of-time-1opc</link>
      <guid>https://dev.to/doylecodes/is-building-your-own-portfolio-a-waste-of-time-1opc</guid>
      <description>&lt;p&gt;When you begin developing applications on your own for the first time, I would argue one of the first things that you do is build a portfolio website.  Maybe you’re entering the job market for the first time and need to show off your skills.  Or, perhaps you want to practice using a new tool, framework, or service. &lt;/p&gt;

&lt;p&gt;While developing your portfolio is a great way to build up your development chops, in this post I’m going to outline some thoughts on why you might NOT want to build your portfolio and opt for using a site-building service instead. &lt;/p&gt;

&lt;h2&gt;
  
  
  Time &amp;amp; Effort
&lt;/h2&gt;

&lt;p&gt;Developing any application on your own takes a lot of time and effort. One advantage over using an existing service (you’ve heard of them: Squarespace, Wix, Carrd, etc.) is that you’ll save a great deal of time when creating your portfolio. You might be thinking, “Exactly what I want! More practice!” While this is true, you could ask yourself, is that what you want to be practicing?  &lt;/p&gt;

&lt;p&gt;I would argue that at a point in your web development journey, you’re going to be practicing lower-level skills when making a portfolio.  Of course, when you are brand new to web development, you need to practice layouts, styles, flexbox, grid, and all the things. Once you get these concepts down, however, I would argue there is no need to continually “practice” these skills.  The world of web development is constantly evolving, and you’ll always have opportunities to practice the basics as you build…well, anything.  Why spend time on a simple portfolio when you could spend time on something more complex?&lt;/p&gt;

&lt;h2&gt;
  
  
  Professional Design
&lt;/h2&gt;

&lt;p&gt;Are you a professional designer? Maybe! But what if you are not?  I for one am not a professional designer. Sure, I can make some cool layouts, but it only takes a quick Google Image search of unique or inspiring designs to remind myself that there are individuals out there in the world who are way more adept at creating compelling visual layouts or thinking of new ways to make information stand out in a sea of similar design.  &lt;/p&gt;

&lt;p&gt;So, could you design your own site? Sure!  But chances are for most of us, that’s not our forte.  There is a reason companies have UI, UX, and graphic designers working for them.  Using a service allows you to avoid competing (visually) with what some of the best out there can do, and allows you more time to focus on developing your skills elsewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessibility and User-Friendliness
&lt;/h2&gt;

&lt;p&gt;One huge advantage to using a website building service for your site is that it’s almost guaranteed to be more accessible and user-friendly. Any good developer should have the capacity to create accessible websites and create a user-friendly UI, but that takes time. All that time you spend trying to make your site fit an endless amount of screen sizes could be a good practice at some point, but is it always the best way to spend your time?  Maybe you have a side project that needs the same attention, and simply offloading that work for your site can allow you to use the same skills elsewhere, where you get more bang for your buck (time-wise). &lt;/p&gt;

&lt;h2&gt;
  
  
  Cost-Effectiveness
&lt;/h2&gt;

&lt;p&gt;You might assume that using a service is going to cost more money than just making a simple. Honestly, that’s probably true if you generate a static site. However, quite often there is a lot of overhead with ensuring your static site is hosted somewhere that allows you to use a custom domain, or involves a lot of time taken when you need to rebuild your website or make a change.&lt;/p&gt;

&lt;p&gt;This essentially brings us back to my first point, again, time and effort.  While it’s possible to make a site for free, it’s almost always going to take you much more time to manage it yourself than to pay a couple of bucks a month for a service that is going to guarantee that x, y, and z are always up and running.&lt;/p&gt;

&lt;p&gt;Consider a simple contact form. You’re going to need a whole email API or rely on some funky form feature (like Netlify forms) that lets you roundabout receive information from a submitted form.  Not super elegant.  Free? Yes. Easy? Debatable.&lt;/p&gt;

&lt;h2&gt;
  
  
  TLDR; Focus on higher-level projects
&lt;/h2&gt;

&lt;p&gt;At the end of the day, my argument is this:&lt;/p&gt;

&lt;p&gt;The purpose of a portfolio is for someone to be able to see your work, get some basic info about you, and perhaps contact you. While all of these features are essential to learn and be comfortable with developing yourself, it’s not very “high-leverage,” meaning…it’s pretty simple at the end of the day. Creating these features from scratch can take a good deal of time and oversight, so once you CAN do this on your own, it’s time to work on more complex projects that will stretch and grow you as a developer. Chances are, you’re still going to be continually creating everything you’d include on a portfolio site anyway.&lt;/p&gt;

&lt;p&gt;So should you make your own portfolio? Maybe?  But it might be time to question whether or not you waste time reworking portfolios constantly instead of spending your time challenging yourself in other ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: What I’m Using
&lt;/h2&gt;

&lt;p&gt;So, what do I use, and why?  &lt;/p&gt;

&lt;p&gt;Currently, my portfolio site is built on carrd.co. I first discovered this site when looking for a simple landing page for my wife.  Turns out, it was a great platform for a simple portfolio. I didn’t want my projects on my site, so much as a landing page for contact, resume, and forwarding anyone who finds it to where I have my actual projects (like Github).&lt;/p&gt;

&lt;p&gt;If I wanted to have some example projects, I could easily add a few.  &lt;/p&gt;

&lt;p&gt;If I wanted a blog, videos, or something else, I’d probably go with something else like SquareSpace, although it’s more expensive and I don’t need/care for those features.&lt;/p&gt;

&lt;p&gt;At the end of the day, it’s simple, but it took me about 20 minutes to get set up and now I have all the time in the day to work on other side projects, Leetcode challenges, or go outside.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>portfolio</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Make a Secure Browser?</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Thu, 06 Aug 2020 01:28:45 +0000</pubDate>
      <link>https://dev.to/doylecodes/make-a-secure-browser-468k</link>
      <guid>https://dev.to/doylecodes/make-a-secure-browser-468k</guid>
      <description>&lt;p&gt;Ok, so I’ve been working on a learning platform for making teacher created playlist of content. One of the next steps is to create some type of quiz situation. &lt;/p&gt;

&lt;p&gt;As a teacher, I’ve used “locked browsers” before, where once a student begins a quiz their browser locks and they cannot navigate away or open new tabs until they either finish the quiz or exit/end it. &lt;/p&gt;

&lt;p&gt;My question is...is there any way to do this from a web dev perspective, or are people just straight up making their own browsers? I can’t seem to find any way to do this from my searching online. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>react</category>
      <category>help</category>
    </item>
    <item>
      <title>Easy Alerts with React Context</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Tue, 16 Jun 2020 21:12:20 +0000</pubDate>
      <link>https://dev.to/doylecodes/making-alerts-for-a-web-app-41d6</link>
      <guid>https://dev.to/doylecodes/making-alerts-for-a-web-app-41d6</guid>
      <description>&lt;h1&gt;
  
  
  What Are We Doing?
&lt;/h1&gt;

&lt;p&gt;For the last few months I've been working on an education based project, and one of the challenges/decisions I had to make was how I was going to handle showing alerts once certain action were completed. There is a lot of content creation involved, so I wanted clear notifications that some action was successful (or not). &lt;/p&gt;

&lt;p&gt;In general I wanted something super simple that just worked to start, but something I could expand later if I wanted to. For starters I just wanted to be able to do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have the alert persist if the page changed, in part so I could send the user to another page and not have to worry about the alert disappearing.&lt;/li&gt;
&lt;li&gt;Look different depending on whether it's responding to a successful action or some error that came up.&lt;/li&gt;
&lt;li&gt;Contain some basic information about what happened, and be able to customize it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  The Solution
&lt;/h1&gt;

&lt;p&gt;I decided to use &lt;em&gt;React Context&lt;/em&gt; to handle the alerts. If you've ever used context before you're probably like, "wow, shocker," but I hadn't seen anything online where someone was making alerts with context before. Usually what I found involved packages and things getting passed back and fourth in server requests, and I didn't want a package, I wanted my own deal.&lt;/p&gt;

&lt;p&gt;So, my solution involved essentially 3 different things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A context High Order Component that wraps the pages in my application with the context provider. (I'm building in Next.js)&lt;/li&gt;
&lt;li&gt;Using the useContext hook to trigger the alert from pages throughout my application.&lt;/li&gt;
&lt;li&gt;An &lt;em&gt;Alert&lt;/em&gt; component that is shown/hidden based on the state of my HOC.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's look at each part so you can mimic/criticize my method 😆.&lt;/p&gt;

&lt;h2&gt;
  
  
  Context Provider HOC
&lt;/h2&gt;

&lt;p&gt;If you're new to React Context, it essentially works on the premise that you can (1) create a context object that hold some type of state, (2) provide the context object to your applications using the context &lt;em&gt;provider&lt;/em&gt;, and (3) use the context &lt;em&gt;consumer&lt;/em&gt; to read the data from the context provider anywhere in your applications.  It's a great way to provide application-wide state without having to pass props from one component to another component a half dozen times.&lt;/p&gt;

&lt;p&gt;Below I have my High Order Component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AlertStatus&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../../lib/enums&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AlertContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;AlertContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;displayName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AlertContext&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AlertProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setAlert&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;None&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;alertText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setAlertText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;AlertContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt;
      &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
        &lt;span class="na"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;alertText&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;alertText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nf"&gt;setAlertText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;setAlert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Success&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;setAlert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;None&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;timeout&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nf"&gt;setAlertText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;setAlert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;setAlert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;None&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;timeout&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="na"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;setAlert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
      &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/AlertContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AlertProvider&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;AlertContext&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Working through the above code, these are the main points:&lt;/p&gt;

&lt;h3&gt;
  
  
  Making the Provider Component
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;First I create the AlertContext and set the display name (for debugging)&lt;/li&gt;
&lt;li&gt;Next, I create the Alert Provider component. With react context, you wrap up the application (or what parts of your app you want the context available to) in the AlertContext.Provider.  The &lt;code&gt;.Provider&lt;/code&gt; is a component available on all Context objects.  So, I am essentially passing in &lt;code&gt;{children}&lt;/code&gt; to my AlertContext.Provider so I can warp up whatever parts of my app in just a &lt;code&gt;&amp;lt;AlertProvider&amp;gt;&lt;/code&gt; component, and it will have the context.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Context &lt;code&gt;value&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;React Context takes a 'value' which is the values that the context consumer can read. I've got 5 different aspects of my Alert value.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;alert&lt;/code&gt; is a simple piece of state (using the useState hook) that is either set to "SUCCESS", "ERROR", or "NONE". In the code you'll notice that it's &lt;code&gt;AlertStatus.None&lt;/code&gt; which is because I'm using typescript. But basically AlertStatus.None is equivalent to "NONE".  You could use strings just as easily but I'm dipping my toes into TS so that's where I'm at. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;alertText&lt;/code&gt; is a string that contains the text that will be shown in the alert.  It's also just a piece of simple state set with the useState hook.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;success&lt;/code&gt; is a method that accepts a string (and optionally a number value). This method changes the value of &lt;code&gt;alertText&lt;/code&gt;, and then sets the alert to "SUCCESS".  The optional number value determines how many seconds will elapse before the &lt;code&gt;clear&lt;/code&gt; method runs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;error&lt;/code&gt; is the same thing as the success, but it set the alert to "ERROR".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;clear&lt;/code&gt; is a method that just sets the alert to "NONE".&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Using the Context Provider HOC in App
&lt;/h2&gt;

&lt;p&gt;I am using Next.js for my application, so I have a custom _app.jsx that has the main structure of my application. Below you can see the entire thing so far.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageProps&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ThemeProvider&lt;/span&gt; &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AlertProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ModalProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Global&lt;/span&gt; &lt;span class="na"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://apis.google.com/js/platform.js"&lt;/span&gt; &lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;css&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;layout&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NavPanel&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ComponentWithRoles&lt;/span&gt; &lt;span class="na"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;pageProps&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;pageProps&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Alert&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Modal&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;ModalProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;AlertProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;UserProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;ThemeProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most import thing to note is that we have the AlertProvider (along with a few other Providers) that is wrapping up the application. I could probably just wrap up the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;, but currently I have it wrapping most everything up, which makes the context available to every component within the &lt;code&gt;&amp;lt;AlertProvider&amp;gt;&lt;/code&gt;. Nice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Triggering Alerts!
&lt;/h2&gt;

&lt;p&gt;Now the best part, triggering alerts! &lt;/p&gt;

&lt;p&gt;Ok, so in my application I am using GraphQL and Apollo, so below I have an example of a Mutation for enrolling a student in a class.  If you're not familiar with Apollo or GraphQL, essentially the mutation is just the part of the logic that's writing information to the database. Within the useMutation hook, there is an object that allows you to do something once the operation has completed, or if there is an error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;AlertContext&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../context/AlertContext&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;EnrollForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;alert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;enroll&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ENROLL_MUTATION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;onCompleted&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Successfully enrolled in class!`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;onError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Ooops, looks like there was a problem. &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="nx"&gt;all&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;other&lt;/span&gt; &lt;span class="nx"&gt;stuff&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, really the only important parts are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Import the AlertContext.  This is exported from the initial HOC component we made.&lt;/li&gt;
&lt;li&gt;Use the React useContext hook to access the Alert Context (which we have access to because it's &lt;em&gt;provided&lt;/em&gt; to our component way up in the component tree).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After that, you can call the methods that were made in the context object!  So in the Apollo useMutation, you are able to execute a callback if the mutation was successful or not. So, within the onCompleted and onError in the Apollo mutation hook (or any other place you would want) you can simply call alert.success, alert.error, or alert.clear from the context! Calling the methods changes the &lt;code&gt;alert&lt;/code&gt; value of the context to the "SUCCESS", "ERROR", or "NONE" which we can use to show an actual alert.&lt;/p&gt;

&lt;h2&gt;
  
  
  Actually Showing Alerts
&lt;/h2&gt;

&lt;p&gt;So, we have logic for alerts set up...but what's actually showing up as an alert?!&lt;/p&gt;

&lt;p&gt;For this, I have another Component, the &lt;code&gt;&amp;lt;Alert&amp;gt;&lt;/code&gt; component. You may have noticed it earlier from above in the entire ._app.&lt;/p&gt;

&lt;p&gt;Here is an ultra simplified version without any styling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Alert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;alert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AlertContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alert&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NONE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hey there, I'm the alert! &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;alertText&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, you gotta pull in the AlertContext using the useContext hook, just like when you want to trigger the alert methods.&lt;/p&gt;

&lt;p&gt;After that we can conditionally render an alert by checking on &lt;code&gt;alert.alert&lt;/code&gt;.  Remember, that would be either "SUCCESS", "ERROR", or "NONE".  So if the value is &lt;em&gt;not&lt;/em&gt; "NONE", the component renders. If the &lt;code&gt;alert.alert&lt;/code&gt; value &lt;em&gt;is&lt;/em&gt; "NONE" then null is returned, so nothing shows. &lt;/p&gt;

&lt;p&gt;The default methods in the alert context will always call the &lt;code&gt;.clear()&lt;/code&gt; method after 10 seconds if nothing else is specified, which will make the alert disappear, but in my actual component I also include a button to close the alert manually using the context.clear(), just like using the success and error methods.  Another thing I do in the real thing is render different styles based on whether or not the &lt;code&gt;alert.alert&lt;/code&gt; is returning "SUCCESS" or "ERROR".&lt;/p&gt;

&lt;p&gt;So, that's it! Feel free to leave thoughts/ideas!&lt;/p&gt;

</description>
      <category>react</category>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Making New Projects with Gatsby &amp; Sanity</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Sun, 20 Oct 2019 01:45:34 +0000</pubDate>
      <link>https://dev.to/doylecodes/making-new-projects-with-gatsby-sanity-30nh</link>
      <guid>https://dev.to/doylecodes/making-new-projects-with-gatsby-sanity-30nh</guid>
      <description>&lt;h1&gt;
  
  
  Why Gatsby &amp;amp; Sanity?
&lt;/h1&gt;

&lt;p&gt;As I've spent more time developing, one thing I have been doing more often is building personal sites for other people. It's an easy way to keep practicing new frontend skills and techniques, as well as build up a portfolio that shows what you can do. One of the most annoying things about this, however, is creating an easy and custom way to manage content for those websites. There are tons of options out there like WordPress, but one of my favorite tools is Gatsby. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why I like Gatsby
&lt;/h3&gt;

&lt;p&gt;Gatsby is a super-fast static site builder with arguably the best documentation I've ever encountered. As a dev, it's an incredible platform. Gatsby is essentially data agnostic, meaning you can use nearly any data type to provide it with content. It could be a WordPress API, markdown, RSS feeds, it's great. Lately, my choice is for managing content easily is Sanity. &lt;/p&gt;

&lt;h3&gt;
  
  
  Why I Like Sanity
&lt;/h3&gt;

&lt;p&gt;Sanity is essentially a super slick headless CMS/backend service. What's great about Sanity is that it comes with the Sanity Studio, a React application that you can run locally or host on a service such as Netlify. The beauty of it is that it allows you to define your own data types. The best way I can imagine explaining how it works (and why you would use it) is to compare it to a CMS such as Wordpress. With WordPress, you have pages and posts, and you can add tags and categories, but beyond that, you would essentially have to massage those types of data in an effort to create a site. That's confusing because the end-user could ultimately be dealing with having to manage data for their website that doesn't really describe their data appropriately. For example, if my wife (an actor) was using a platform such as Wordpress as a CMS and wanted to add a recent show that she performed to her resume, she might be making a new "Post" with a category. It works, but with Sanity, you could make your own data type called "Show" in the schema and that automatically creates a document type that could be edited by her (the end-user). For another example, I'm currently working on a site for a woodworker. They might want an area of their website that catalogs the different types of wood along with the wood properties for their readers. Using Sanity, I can make my own data-type for that. The great thing about Sanity is that you have the flexibility to create custom ways to store your data and manage your content (you can even edit the Sanity Studio itself because it's just a React app) all &lt;strong&gt;without&lt;/strong&gt; having to set up your own database and manage all of that. For me, it's a happy space of having a custom CMS I can make for a particular client while not actually having to develop &lt;em&gt;everything&lt;/em&gt; from scratch.&lt;/p&gt;

&lt;h1&gt;
  
  
  What We're Doing
&lt;/h1&gt;

&lt;p&gt;In this post, I am going to be going over how to create a brand new, clean project in Gatsby and connecting it to Sanity as it's the primary data source. The Sanity site actually has a few starters you can use with just a few clicks, but it comes with a lot of pre-defined CSS, as well as the clutter of all the sample files that I don't necessarily want to deal with when starting a new project. Following these steps, you can grasp the basics of how Sanity and Gatsby work together and have a clean setup for both so you can use whatever you want for development, such as styling, file structure, etc. Here we go!&lt;/p&gt;

&lt;h1&gt;
  
  
  Steps
&lt;/h1&gt;

&lt;h3&gt;
  
  
  1 - Create Directory
&lt;/h3&gt;

&lt;p&gt;So first we are going to create a directory for our project. I do this first because the CLI tools for Gatsby and Sanity are a little different and I also prefer to have both under a single git repo, so go ahead and make a directory named whatever, wherever you want.  I named mine &lt;strong&gt;gatsby-sanity-starter&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2 - Create Sanity Studio
&lt;/h3&gt;

&lt;p&gt;First, you need to &lt;a href="https://www.sanity.io/docs/getting-started-with-sanity-cli"&gt;install the Sanity CLI&lt;/a&gt;, so using npm run &lt;code&gt;npm install -g @sanity/cli&lt;/code&gt; to install the CLI globally. After that, make a &lt;em&gt;new&lt;/em&gt; directory in your root directory and name it &lt;em&gt;studio&lt;/em&gt;. From the studio directory, run &lt;code&gt;sanity init&lt;/code&gt;.  The first time you do this you'll need to log in, create an account, and when prompted for a project, you are going to select &lt;strong&gt;Create a New Project&lt;/strong&gt; and then for the project template you want to select &lt;strong&gt;Clean project with no defined schamas&lt;/strong&gt;. This is going to create a brand new Sanity Studio inside the /studio directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  3 - Create a Gatsby Site
&lt;/h3&gt;

&lt;p&gt;If you have not already, &lt;a href="https://www.gatsbyjs.org/tutorial/part-zero/"&gt;install the Gatsby CLI&lt;/a&gt; with &lt;code&gt;npm install -g gatsby-cli&lt;/code&gt;. Next, you're going to go to your root directory and run &lt;code&gt;gatsby new web&lt;/code&gt;, which creates a new Gatsby project within the /web directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  4 - Remove git from the Gatsby site
&lt;/h3&gt;

&lt;p&gt;Next, we are going to remove git from the Gatsby site in the /web directory. This can be done by running &lt;code&gt;rm -rf .git&lt;/code&gt; from within the /web directory. I prefer to do this because I like having a single git repo for both the studio (in /studio) and the actual website (in /web). Alternatively, you could run &lt;code&gt;git init&lt;/code&gt; from within the /studio directory and have two separate repos for the studio and the website.&lt;/p&gt;

&lt;h3&gt;
  
  
  5 - Install gatsby-source-sanity
&lt;/h3&gt;

&lt;p&gt;If you're new to Gatsby, a basic principle is that it uses plugins to incorporate various features. The plugin &lt;a href="https://www.gatsbyjs.org/packages/gatsby-source-sanity/?=sanity"&gt;gatsby-source-sanity&lt;/a&gt; allows you to run GraphQL queries in your Gatbsy app against a GraphQL API route created by Sanity. You install this in a few steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;From within the /web directory, run &lt;code&gt;npm i gatsby-source-sanity --save&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add the plugin config to the file gatsby-config.js
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// in your gatsby-config.js&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gatsby-source-sanity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;abc123&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blog&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// a token with read permissions is required&lt;/span&gt;
        &lt;span class="c1"&gt;// if you have a private dataset&lt;/span&gt;
        &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MY_SANITY_TOKEN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Within the plugin config, you need to replace the &lt;em&gt;projectId&lt;/em&gt; and &lt;em&gt;dataset&lt;/em&gt; with your Sanity project id and dataset name. You can find this in the &lt;strong&gt;/studio/sanity.json&lt;/strong&gt; file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6 - Create Your Schema
&lt;/h3&gt;

&lt;p&gt;At this point, in order to check everything is up and running properly in terms of the connections between your Gatsby site and Sanity you'll need to create some type of basic Schema. When we created a new Sanity site, it is 100% void of any schema, so there isn't a way to see anything getting pulled into you Gatsby site. We will do this in 2 steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the file &lt;em&gt;blogPost.js&lt;/em&gt; and &lt;em&gt;sponsor.js *in the schemas directory so you have */studio/schemas/blogPost.js&lt;/em&gt; and &lt;em&gt;/studio/schemas/sponsor.js&lt;/em&gt; with the following.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// in blogPost.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blogPost&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Blog post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// ... other fields ...&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sponsor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sponsor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sponsor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// in sponsor.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sponsor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sponsor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;url&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;URL&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;url&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Import blogPost and sponsor into the types in &lt;em&gt;schema.js&lt;/em&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;createSchema&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;part:@sanity/base/schema-creator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;schemaTypes&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;all:part:@sanity/base/schema-type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;blogPost&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./blogPost&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;sponsor&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./sponsor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;createSchema&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;default&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;schemaTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="cm"&gt;/* Your types here! */&lt;/span&gt;
    &lt;span class="nx"&gt;blogPost&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;sponsor&lt;/span&gt;
  &lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;If you want to check out more about creating schemas in Sanity, the &lt;a href="https://www.sanity.io/docs/content-modelling"&gt;docs are here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  7 - Deploy GraphQL API
&lt;/h3&gt;

&lt;p&gt;Anytime you modify your schema, you have to deploy your schema again so that your GraphQL API knows what's available to query. Since we just added a blogPost type and a sponsor type we need to deploy the API.  We do this from /studio with the command &lt;code&gt;sanity graphql deploy&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  8 - Make Sample Blog Post
&lt;/h3&gt;

&lt;p&gt;From /studio go ahead and run &lt;code&gt;sanity start&lt;/code&gt;, and you can open up the Studio from localhost:3000. Here you should see the "Blog post" under Content, and you can click on that, and then the + button to create your first post. Just type in some filler info and move to the next step.&lt;/p&gt;

&lt;h3&gt;
  
  
  9 - Build Gatsby Site
&lt;/h3&gt;

&lt;p&gt;Gatsby is a static site builder, so we need to build the site.  Do this from /web with &lt;code&gt;gatsby develop&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once the site is built, you should be able to see the generic Gatsby starter page from &lt;em&gt;localhost:8000&lt;/em&gt;, but if you head over to &lt;strong&gt;localhost:8000/__graphql&lt;/strong&gt; you can see the graphQL playground.  If all went well, there should be a few queries on the left that have Sanity in it, such as &lt;em&gt;allSanityBlogPost&lt;/em&gt;.  At this point, you can try running the query below and you should get data returned containing your blog post data you made.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="k"&gt;query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MyQuery&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;allSanityBlogPost&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;totalCount&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="n"&gt;_id&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  That's It!
&lt;/h1&gt;

&lt;p&gt;Hopefully, now you have a clean Gatsby site hooked up to a Sanity Studio!  From here, you can develop a Gatsby site however you normally would while you have new custom headless CMS through Sanity.  Let me know how it goes!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/7n4r8CE1YkDGU/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/7n4r8CE1YkDGU/giphy.gif" alt="success" width="279" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gatsbyjs.org/blog/2019-01-25-blazing-fast-development-with-gatsby-and-sanity-io/"&gt;You can read more about Gatsby and Sanity from the source.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>sanity</category>
      <category>graphql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>GIT for Dummies</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Sun, 29 Sep 2019 00:03:01 +0000</pubDate>
      <link>https://dev.to/doylecodes/git-for-dummies-1a2i</link>
      <guid>https://dev.to/doylecodes/git-for-dummies-1a2i</guid>
      <description>&lt;h1&gt;
  
  
  Background
&lt;/h1&gt;

&lt;p&gt;Ok, it's been a long time since I wrote a post.  I thought maybe something super easy would be helpful for me to get going again. A few months back I did my first hackathon for an open-source project with Code4Sac.  It was a great experience and one of the best things I gained was working with git for the first time on a project with other people. I know there are many ways that teams use git together, but I thought I would write up a quick list of commands you would want to know to get started working with others, as well as what they do.  Finally, I'll sum it all up with a basic workflow example using all the commands.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;Ok, first things first. You want to start a new project. Where do you start? If I was new to git/GitHub and wanted to have the easiest setup, I would start by creating a repo on Github. Starting this way will allow you to avoid having to hook up your existing project on your local machine with the remote repository on GitHub. (Yes there are sites other than Github, but if you are starting that's probably where you are) &lt;/p&gt;

&lt;p&gt;So, head over to Github, make a new repository for your project then let's get started with the commands...&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F16d9v3jmd1de4pphzmve.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F16d9v3jmd1de4pphzmve.PNG" alt="Make a repo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The Commands
&lt;/h1&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;git clone&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With a brand new repo, you get an area that says "Quick Setup with a link to your repo. Copy that.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foixk4e9ty7u82qnohwg2.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foixk4e9ty7u82qnohwg2.PNG" alt="clone link"&gt;&lt;/a&gt;&lt;br&gt;
Alternatively, in an older repo, you'll have a nice green button that says "Clone or Download".  There you can copy a link. &lt;/p&gt;

&lt;p&gt;Head over to your terminal, then navigate to the directory you would want to have your new project in. Here you are going to enter the command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 clone your_repo_link_here

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

&lt;/div&gt;

&lt;p&gt;Typing this command will make a copy of the entire repo on your local machine within a directory that has the repository name, and link it to the repository.(You can also copy the repo into the &lt;em&gt;current&lt;/em&gt; directory, just place a "." at the end of the command)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;git pull origin master&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With a new project, you wouldn't need to pull, but after you start working on your project, or once you are working with others contributing to a project you'll need to make sure your repo is up to date. You do this by "pulling" the code down from your remote repository.  We do this with:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 pull origin master

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

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;A quick note on what a REMOTE repository is. When you have git running on your computer locally, that's a repository just like the repository on Github. The term remote refers to a repository somewhere else.  Most often when starting out, especially in this tutorial, the remote repository is also the "origin," where the repository was originally cloned from.  But you could have multiple remote repositories, set up across different computers for example, and be able to update all of them from one computer. In this case, the remote repository just means the repo on Github we started with&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, basically this is the command you would use to make sure your local repo is up to date with the repo on Github. In this case, we are pulling from the &lt;strong&gt;origin&lt;/strong&gt;, which is the remote repository that the project was cloned from (we cloned it from Github, so it's the origin of the repo) and we want to pull the code thats in the &lt;strong&gt;master&lt;/strong&gt; branch.&lt;/p&gt;

&lt;p&gt;In the future, you might work on other branches on the repository, in that case, you could pull down the code from Github by typing &lt;code&gt;git pull origin whatever_branch_name_here&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;git checkout&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Ok!  so let's says you're going to be doing some work now in your project.  Generally, you want to do your work on a &lt;strong&gt;branch&lt;/strong&gt;. A branch is essentially a copy of the project at a given point in time, and it allows you to work on the codebase without actually working on THE codebase. In a production environment, the idea is you wouldn't want to be directly editing the code that's running the show, so you take a copy, work with that, and later on combine your edits into the &lt;strong&gt;master branch&lt;/strong&gt;, where all the magic is actually happening.&lt;/p&gt;

&lt;p&gt;My favorite way to make a new branch is to use the command &lt;code&gt;git checkout -b new-branch-name&lt;/code&gt;.  Technically there is the &lt;code&gt;git branch&lt;/code&gt; command to make a branch, and &lt;code&gt;git checkout&lt;/code&gt; command to switch to a branch, but the &lt;code&gt;git checkout -b&lt;/code&gt; with a name after allows you to make a new branch and switch to it all at once!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;git add&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Alright, so it's been a few minutes now and you've got some code typed up. You want to get that code on your local machine up to Github now everything is synced up. First, you need need to add the files you want to the "staging" area.  Basically, up until this point, git knows you have made changes to some files but you have to say, "OK, not I am going to do something with all of these files here."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Super important note, you probably want to add a .gitignore file at the root of your project.  In here you can add files to automatically ignore. You would definitely want to put in &lt;code&gt;node_modules&lt;/code&gt;, as well as other things yo don't want to be tracked such as .env variables, or generated folders from things like Next, Gatsby, create-react-app, etc. You do this by typing the name of the file and/or folder on each line, separately.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I typically try and do this regularly as I work on each particular aspect/feature, so usually I add all my files at once to the staging area by typing in &lt;code&gt;git add *&lt;/code&gt; but if you want to, you can add files individually by using &lt;code&gt;git add filepath/name_here&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;git commit&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once files are in the staging area, it allows us to make a &lt;strong&gt;commit&lt;/strong&gt;, which kind of like saving everything at a point in history in git. Commits are nice because we can easily go back to certain commits if needed, as well as leave comments about what changes we made to help keep track of changes in our code.&lt;/p&gt;

&lt;p&gt;So to make a commit, we use the command:&lt;br&gt;
&lt;code&gt;git commit -m 'descriptive message here'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's basically it. The -m allows us to add a description immediately after.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;git push&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now the part that actually syncs things up!&lt;/p&gt;

&lt;p&gt;Thus far, basically everything has been on your local machine, but once you've made a commit (or a few) we can push all of the commits up to Github and the origin/remote repo online will mirror what we have on our machine.&lt;/p&gt;

&lt;p&gt;Since you SHOULD be working on a branch, you would use the command:&lt;br&gt;
&lt;code&gt;git push origin the_branch_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After pushing to the branch, you would be able to Github, see the branch, and do a &lt;strong&gt;pull request&lt;/strong&gt; (or PR to the cool kids) that will pull the code from your branch into the master branch. Pulling your code into the master is what merges your changes to the master branch, which would be the main source of truth for everyone and the code in production (in most cases).&lt;/p&gt;

&lt;p&gt;If you're being &lt;em&gt;naughty&lt;/em&gt; or just working on your own project you might also do:&lt;br&gt;
&lt;code&gt;git push origin master&lt;/code&gt;&lt;br&gt;
which bypasses the PR process and immediately pulls your new code into the master branch.  Don't do that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/LRKET0Syb0rDO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/LRKET0Syb0rDO/giphy.gif" alt="nope"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Workflow
&lt;/h1&gt;

&lt;p&gt;Alright, so that's basically what I've used to get things done.  But here is a scenario where you use all of them...&lt;/p&gt;

&lt;p&gt;You're working on a project with a few people, it's been a few hours or days since you've worked on the project. You sit down on your comp and...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;git pull origin master&lt;/code&gt;: Make sure everything is up to date! You might also pull from a branch you are working on instead of the master branch by using &lt;code&gt;git pull origin branch_name&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -b some-branch-name&lt;/code&gt;: Make and checkout (go to) and new branch for your work, so you don't mess up what others are doing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git add *&lt;/code&gt;: Add all the files you changed so you can make a commit once you've actually done something.&lt;/li&gt;
&lt;li&gt;`git commit -m 'some helpful comment': Commit your changes so you can send the changes to the remote repository.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push origin branch-name&lt;/code&gt;: Push all your commits up to the remote repository on Github to your specific branch.&lt;/li&gt;
&lt;li&gt;Make a PR on Github.  Your code after pushing is still in a separate branch online, so you need to make a pull request to merge it into the master codebase.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nice job! You did work, kept everything synced up, and hopefully didn't screw up someone else's code!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1GlDW1HBD3q2A/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1GlDW1HBD3q2A/giphy.gif" alt="nice job"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Getting Started with PostgreSQL</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Fri, 14 Jun 2019 23:25:45 +0000</pubDate>
      <link>https://dev.to/doylecodes/getting-started-with-postgresql-5g29</link>
      <guid>https://dev.to/doylecodes/getting-started-with-postgresql-5g29</guid>
      <description>&lt;h2&gt;
  
  
  Why PostgreSQL?
&lt;/h2&gt;

&lt;p&gt;In this post, I am going to be looking at creating a managed PostgreSQL (which from now on I'm just going to call a SQL database) and connecting to it using &lt;em&gt;node_postgres&lt;/em&gt;. I have a decent amount of experience using MongoDB databases and have built a fairly good sized project using Prisma, which uses SQL behind the scenes but I had not ever had to actually write a SQL query and interact directly with a SQL database.&lt;/p&gt;

&lt;p&gt;With Mongo Atlas (or mLab) and mongoose, it was extremely easy for me to find out how to get up and running but I was having a hard time just getting up and running with my own SQL database. &lt;/p&gt;

&lt;p&gt;Here were the considerations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I didn't want to use some weird free website that I would never be able to use in production.&lt;/li&gt;
&lt;li&gt;I wanted it to be cheap (I was maybe successful?!)&lt;/li&gt;
&lt;li&gt;It needed to be a real solution that I could see myself using in a real Node application. (opposed to using something like a GoDaddy server with a bunch of databases set up for me already)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without further ado, here is what I'll be walking through:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Getting a DB up and running with DigitalOcean.&lt;/li&gt;
&lt;li&gt;Setting up the config for your project in Node with node-postgres.&lt;/li&gt;
&lt;li&gt;Creating a table and testing it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Creating a PostgreSQL Database
&lt;/h2&gt;

&lt;p&gt;If you haven't used DigitalOcean yet, it's pretty great. In short its a site where you can set up virtual servers among other things. At first, I tried to set up my own server with MySQL installed (which would have been about $5 a month to run) but that was becoming a bit of a beast to figure out, and ultimately my goal was to just be able to access a SQL database to be able to write a frontend application so I didn't want to spend all my time there. So...&lt;/p&gt;

&lt;p&gt;I settled on a DigitalOcean managed database. That costs $15 a month, but it's cheaper than a course, it's legit, I saved me a bunch of time (I mean, people have full-time jobs managing databases) and DigitalOcean gives you referral codes that let you get credits for a certain amount of time (usually 30-60 days) and I had credit so it was free to try! If you want to give it a try &lt;a href="https://m.do.co/c/e3e79529827f" rel="noopener noreferrer"&gt;sign up using my referral code&lt;/a&gt; and you can get $50 in credits for 30 days so it's free for you to get started.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up the DigitalOcean Database
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://m.do.co/c/e3e79529827f" rel="noopener noreferrer"&gt;Sign up for DigitalOcean&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Create a new project&lt;/li&gt;
&lt;li&gt;Create a managed database. I used the PostgreSQL, which at the time of writing is the only option. You'll need to set up some options here but it's pretty self-explanatory.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1dwsn4o4uqcz558kslhd.PNG" alt="create managed database" width="798" height="762"&gt;
&lt;/li&gt;
&lt;li&gt;The database will get created and you can see it in your project. Go to it to complete the setup.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwh82x179tmwybxhfyrx.PNG" alt="db list" width="587" height="283"&gt;
&lt;/li&gt;
&lt;li&gt;Add your IP address so the database access isn't open to the public.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxhxlw0xvuahz8zkxaonl.PNG" alt="ip address" width="800" height="433"&gt;
&lt;/li&gt;
&lt;li&gt;Download the SSL certificate, which we will use to connect.
&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwn8unvk20esxhx5xps2.PNG" alt="ssl" width="800" height="542"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Nice job! Your database is up and running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting to Database
&lt;/h2&gt;

&lt;p&gt;I'm not trying to write a tutorial on how to make a whole application, so we are just going to tackle a few steps here.  First, we will set up node-postgres, and then we will write a basic query to make a new table and log it to the console.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project setup
&lt;/h3&gt;

&lt;p&gt;To connect you only need 2 things, a .js file for conecting, and the .crt certificate you downloaded from DigitalOcean.  Here is my structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgresql-tutorial
  /certificate.crt (I renamed this)
  /connect.js (you can name whatever you want)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Set Up Connection
&lt;/h3&gt;

&lt;p&gt;First, here is what I have to connect to my database. I got everything from the &lt;a href="https://node-postgres.com/" rel="noopener noreferrer"&gt;docs on node-postgres&lt;/a&gt;, but I left comments within to explain each part. You access all of the config options from your DigitalOcean, as seen from the photo below.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F451dw7c8rbbyuxx4fp7t.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F451dw7c8rbbyuxx4fp7t.PNG" alt="config options" width="572" height="367"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// node-postgres also support a pool connection, but I was more familiar with the Client type so I started with that&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Client&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// fs is used to read the certificate&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// everything here you can get from the "Connection Details" when viewing your database in DigitalOcean&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;doadmin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;db-postgresql-nyc1-21328-do-user-4669604-0.db.ondigitalocean.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;defaultdb&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tqjgkd6uxyqger6n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25060&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="cm"&gt;/* You have to include the ssl options because DigitalOcean requires them.
  This is essentially just added on from the boilerplate config in the node-postgres docs */&lt;/span&gt;
  &lt;span class="na"&gt;ssl&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;rejectUnauthorized&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;ca&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./certificate.crt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="c1"&gt;//make sure name matches your certificate name you downloaded&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// creates a new Client instance with the config options above (you can also just put them directly in as argument)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Connects! (Or tells me I don't know what I'm doing)&lt;/span&gt;
&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Connection error!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Connection to DB successful&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Testing out the database
&lt;/h3&gt;

&lt;p&gt;With the code above (and your own config options since the ones above won't work anymore) you should see in your console that you are connecting. From here, it's pretty easy to work with the database.  Basically, node-postgres has &lt;a href="https://node-postgres.com/features/queries" rel="noopener noreferrer"&gt;queries&lt;/a&gt; where you pass in a SQL query. I'm not getting into that much, after all, this was to get better at that in the first place. The query, if successful, will return a response object. &lt;/p&gt;

&lt;p&gt;In the same connect.js file, add the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;makeTable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
  CREATE TABLE products (
  product_no integer,
  name text,
  price numeric
);`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;testQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`SELECT * FROM products`&lt;/span&gt;

&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;makeTable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//pass in the testQuery to see if making the table was successful&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;After adding those line, you should be able to run &lt;code&gt;node connect.js&lt;/code&gt; and see a response object returned.&lt;/p&gt;

&lt;p&gt;Essentially, client.query is taking in the makeTable SQL query (that I got from the &lt;a href="https://www.postgresql.org/docs/11/dml-insert.html" rel="noopener noreferrer"&gt;PostgreSQL docs&lt;/a&gt;) which is a promise that will either log the response that's returned or log the error.  Finally, the connection is closed.&lt;/p&gt;

&lt;p&gt;You can see there is a second query &lt;code&gt;testQuery&lt;/code&gt; which you can pass into &lt;code&gt;client.query&lt;/code&gt; (replacing makeTable) and you should be able to get another response object that shows the details of the table you created at first.&lt;/p&gt;

&lt;p&gt;That's it. Hopefully, someone else can find this useful and get up and running playing around with SQL in a real application!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I made this post pretty quick as my hands froze to death in and over-airconditioned Starbucks, so if something seems unclear please let me know so I can revise and clarify!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Java, C++, or C#???</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Wed, 05 Jun 2019 03:22:32 +0000</pubDate>
      <link>https://dev.to/doylecodes/java-c-or-c-1a8l</link>
      <guid>https://dev.to/doylecodes/java-c-or-c-1a8l</guid>
      <description>&lt;p&gt;Alright. I would consider myself a new developer. I have worked primarily with Node, Javascript, and React and have been looking to enter the workforce as a developer.&lt;/p&gt;

&lt;p&gt;In my search for a new career, I am of course always looking to develop my skills and learn more. As I look online (granted, this might just be in my area) I see a LOT of open positions for .NET, and many backend jobs looking for experience with Java. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Question
&lt;/h2&gt;

&lt;p&gt;My question is, as someone who would consider themself to be pretty strong on the Javascript/Node front, &lt;strong&gt;what would be a more beneficial programming language to seek out learning next? Would learning Java, C++, or C# make me a better programmer?&lt;/strong&gt;*&lt;/p&gt;

&lt;h2&gt;
  
  
  Here are my first thoughts for each:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Java&lt;/strong&gt;: It's all over the place, so it seems like it would be good ont he resume as well as a skill overall to understand. My first interview I bombed because it was for a backend Java position. (I applied for a Node/JS frontend position)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;C++&lt;/strong&gt;: It closely related to C (in my understanding). Apparently that can help a lot with other languages based on C. Also, I've heard it's good because it doesnt manage things like memory automatically so it makes you a better developer in the sense that you need to understand aspects of how the language works a little more than you might with other languages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt;: Somewhat like C? Also it's part of the .NET stack which seems to have many jobs out there.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*I'm not necessarily looking for the best language to get a job right away. I'm trying to think more long term. That thinking leads me towards C++ because of what I said above, but not knowing any of these languages, I am hoping someone might have some more insight! I'd rather learn a language with skills that can apply across the board than something really specific to a certain stack, but then my locked in to that.&lt;/p&gt;

&lt;p&gt;Or...maybe go the totally other direction and go with Swift?!&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>csharp</category>
      <category>java</category>
      <category>discuss</category>
    </item>
    <item>
      <title>CORS in Apollo Client &amp; Apollo Server</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Wed, 01 May 2019 17:00:03 +0000</pubDate>
      <link>https://dev.to/doylecodes/cors-in-apollo-client-apollo-server-3cbj</link>
      <guid>https://dev.to/doylecodes/cors-in-apollo-client-apollo-server-3cbj</guid>
      <description>&lt;h2&gt;
  
  
  This is a follow-up
&lt;/h2&gt;

&lt;p&gt;Ok, a while back I asked a question and spent a few days trying to figure this out.  I'm hoping that this can direct someone trying to solve the problem in the right direction.  As a reference, this is the original post.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/doylecodes" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F138063%2Ff7de534e-9cd6-412b-ab34-893e2c28ab58.jpeg" alt="doylecodes"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/doylecodes/graphql-server-not-setting-jwt-cookie-1gme" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;GraphQL Server Not Setting JWT Cookie&lt;/h2&gt;
      &lt;h3&gt;Ryan Doyle ・ Mar 31 '19&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#help&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#express&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#apollo&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  My problem
&lt;/h2&gt;

&lt;p&gt;So, my problem was that I had set up an Apollo Server with the backend hosted from a /backend directory and the frontend hosted from a separate directory at /frontend.  My frontend was running on localhost:3000 and the backend I had running at localhost:4000. I was running into various problems with CORS as I tried to pass cookies along with requests, and I couldn't figure out what was going on. I also had a difficult time figuring out how to pass certain things (like user data) with requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My problem was, I was trying to pass along specific cors options, and I didn't know that Apollo Server came with default cors settings.  Those settings were overriding and conflicting with what I needed&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;My solution ended up being 2 parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using the package &lt;code&gt;apollo-server-express&lt;/code&gt; and the cors middleware.&lt;/li&gt;
&lt;li&gt;Disabling the Apollo Server cors to avoid conflicts.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Prisma&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prisma-binding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloServer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apollo-server-express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;importSchema&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-import&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cookieParser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cookie-parser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;typeDefs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;importSchema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/schema.graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/resolvers/Query&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Mutation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/resolvers/Mutation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Prisma&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./generated/prisma.graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_ENDPOINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DB_SECRET&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApolloServer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;resolvers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Mutation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;Query&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;corsOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FRONTEND_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;-- REQUIRED backend setting&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;corsOptions&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cookieParser&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// checks for user in cookies and adds userId to the requests&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookies&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;USER_SECRET&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{id, permissions, email, name}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;//the graphql query to pass to the user query&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;applyMiddleware&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// disables the apollo-server-express cors to allow the cors middleware use&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`🚀 Server ready at http://localhost:4000&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;graphqlPath&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This is my server/app set up as of now with everything working perfectly! Here are the main points and why I ended up implementing it that way.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using &lt;code&gt;apollo-server-express&lt;/code&gt; instead of &lt;code&gt;apollo-server&lt;/code&gt;:&lt;/strong&gt; This essentially allows you to create an express app and pass it to the server instead of using the vanilla app that Apollo Server creates on its own.  It also allows you to create middlewares just as you would with a generic express based application and server!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;app.use(cors(corsOptions)):&lt;/strong&gt; For more granular cors options (I wanted the server to only listen to localhost:3000) you use the cors middleware and the options to listen to the origin you want, as well as the option to pass on credentials with requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;server.applyMiddleware:&lt;/strong&gt; It is here that you pass to the Apollo Server the express application, as well as the other important part, &lt;strong&gt;turn off the default cors options&lt;/strong&gt;.  Even though you turn off the default options, you are using the cors middleware in the express app you pass to the server, so it's all handled there.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>apollo</category>
      <category>tutorial</category>
      <category>react</category>
      <category>express</category>
    </item>
    <item>
      <title>GraphQL Basics - Part 5: GraphQL Queries in Apollo Client</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Tue, 30 Apr 2019 18:44:05 +0000</pubDate>
      <link>https://dev.to/doylecodes/graphql-basics-part-5-graphql-queries-in-apollo-client-2ibd</link>
      <guid>https://dev.to/doylecodes/graphql-basics-part-5-graphql-queries-in-apollo-client-2ibd</guid>
      <description>&lt;h2&gt;
  
  
  GraphQL Queries
&lt;/h2&gt;

&lt;p&gt;To get started with GraphQL queries we are going to first take a look at what a GraphQL query looks like, then we are going to see what writing a query looks like in Apollo on the front end.&lt;/p&gt;

&lt;p&gt;If you've been following along with this tutorial, we have the following data model so far:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;unique&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;itemId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;unique&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
  &lt;span class="nx"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Int&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
  &lt;span class="nx"&gt;shortDescription&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
  &lt;span class="nx"&gt;longDescription&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using GraphQL we can write a query for a specific user the following way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="nx"&gt;GET_USER_QUERY&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;id&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here what each level has going on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;query GET_USER&lt;/code&gt;: This establishes we are writing a query, and we give it the name GET_USER_QUERY. I just like to add 'query' or 'mutation' in the names for clarity sake.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;user&lt;/code&gt;: This is the specific query. It's also what our Apollo Server is going to look for in the &lt;strong&gt;Resolvers&lt;/strong&gt;. Basically, we are telling the graphQL server to run the "user" resolver, which is similar to making a request from website.com/user in a REST API.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;id, name&lt;/code&gt;: Finally, inside of &lt;code&gt;user&lt;/code&gt;, we state what we want to be returned, which is both the id and the name of the user. (Although, we could just ask for one of them if we wanted)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  REST API and GraphQL Compared
&lt;/h2&gt;

&lt;p&gt;If you are coming from the land of a REST API, this is a little different. Basically, with a REST API, you end up hitting a certain URL endpoint, such as &lt;em&gt;somesite.com/user&lt;/em&gt; and passing a query or params to the URL. You could use an express server to take those query params and use them in whatever logic to talk to the database and return data to you. (Super brief explanation obviously, I'm assuming you have some familiarity)&lt;/p&gt;

&lt;p&gt;In a REST API, you have endpoints that you hit for certain requests/posts. An example would be &lt;em&gt;website.com/users&lt;/em&gt; to get a list of users or going to &lt;em&gt;website.com/posts&lt;/em&gt; for a full list of posts. You need an endpoint for all the different requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With GraphQL your server is set up to accept all requests the same way, but similar to how a REST API has different endpoints where the logic for the requests goes, a GraphQL server has different &lt;em&gt;RESOLVERS&lt;/em&gt; that tell each GraphQL how to be handled.&lt;/strong&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%2Frzs0vzzfds0vgl2kk8bl.gif" 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%2Frzs0vzzfds0vgl2kk8bl.gif" alt="Mind Blown"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing the GraphQL Query from Frontend
&lt;/h2&gt;

&lt;p&gt;Again, if you've been following along in the series, when we set up our graphQL server initially we were able to run queries against the sandbox endpoint (localhost:4000 on our project). That's great but, we need to be able to run the queries from our application, here's how we could do that!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adding Users to Prisma DB&lt;/strong&gt;&lt;br&gt;
First thing's first, we need to add a few users to our database in order to have something to query. We could do this programmatically, but I think that queries are easier to start within GraphQL, Prisma, and Apollo so what I did was just go into my Prisma DB, and add some users directly from the Prisma Admin.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsux4a42xm110otqez7rt.JPG" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsux4a42xm110otqez7rt.JPG" alt="Prisma Admin Console"&gt;&lt;/a&gt;&lt;br&gt;
Go to your Users in the admin console, and there is a + button (I highlighted it in yellow in the photo above) where you can just click to add users directly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Add graphql-tag&lt;/strong&gt;&lt;br&gt;
We need to add the package &lt;a href="https://github.com/apollographql/graphql-tag" rel="noopener noreferrer"&gt;graphql-tag&lt;/a&gt; to our project. This lets us use template literals to parse the GraphQL language into out Apollo Queries. Simply &lt;code&gt;npm i graphql-tag&lt;/code&gt;!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Make a Users Component&lt;/strong&gt;&lt;br&gt;
Ok! So to write a query, we first need a component. We first need to create a file named &lt;em&gt;Users.js&lt;/em&gt; in our projects frontend/components directory. Inside we need to require a few things (in addition to the normal react stuff dependencies).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;graphql-tag: For wrapping out GraphQL queries.&lt;/li&gt;
&lt;li&gt;Query: The Query render prop from the react-apollo library.
We should have a basic start like below:
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-apollo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


  &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Users&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;m the user component.&amp;lt;/p&amp;gt;
      );
    }
  }

  export default Users;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Add GraphQL Query to the User Component&lt;/strong&gt;
Next, we need to add the actual query. To get a better idea of the flow of writing a query from scratch, we are going to be making a query to get ALL users. To do this we use the gql tag and create a variable that holds the query in the gql tag.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GET_USERS_QUERY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  query GET_USERS_QUERY {
    users {
      id
      name
    }
  }
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using the Query Component in Apollo Client&lt;/strong&gt;
To run our query, we use the Query component from Apollo Client. This is essentially a render prop that accepts our query as a prop, and behind the science runs the query against the database and returns data for us to work with!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To start off making sure everything is working, within the class we can put our  component, passing the query as a prop, and within that, we have a single function that returns "data".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Users&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;GET_USERS_QUERY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;check&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Query&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see how our function accepts data that get returned from the query, and currenlty we are simply returning a paragraph tag that say "check log" because we are logging the data to the console.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Make a User Page&lt;/strong&gt;
To see anything we need to make a new page that we can navigate to in our application.  In the frontend/pages directory, I made a new file named &lt;em&gt;users.js&lt;/em&gt; and put the following:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Users&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../components/User&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Users&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because we are using Next.js, making a new component in the /pages directory will create the &lt;em&gt;users&lt;/em&gt; route and that's where we put out Users component.&lt;/p&gt;

&lt;p&gt;Now we should be able to go to &lt;strong&gt;localhost:3000/users&lt;/strong&gt;, and see our data in the logs!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OOPS.  Fixing Errors&lt;/strong&gt;
Ok, if you have been following along 100% you now see errors. Full disclosure, I didn't plan this all out ahead of time and one problem I realized along the way is when setting up our servers, there are some CORS problems due to our frontend and backend being from different locations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can all be fixed by changing our &lt;em&gt;backend/index.js&lt;/em&gt; to look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Prisma&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prisma-binding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloServer&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apollo-server-express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;importSchema&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-import&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;typeDefs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;importSchema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/schema.graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/Query&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Mutation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/Mutation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Prisma&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./generated/prisma.graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://us1.prisma.sh/prisma-tutorial/prisma-graphql-tutorial/dev&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;currentlyDrinkingPhilzCoffee&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApolloServer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;resolvers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Mutation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;Query&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;db&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;corsOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:3000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// includes headers for the requests to backend&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;corsOptions&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;applyMiddleware&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;// disbles default apollo-server cors and uses the express middleware cors in-lieu. &lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`🚀 Server ready at localhost:4000`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is pretty similar to what we had before with one major adjustment. (Hopefully, the reasoning will be another post later on...)  Apollo Server actually handles CORS by default, and this becomes a problem if your frontend and backend are hosted in different places. Essentially what I've done here is this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changed const &lt;code&gt;{ ApolloServer } = require('apollo-server')&lt;/code&gt; to &lt;code&gt;require('apollo-server-express')&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Created an express app&lt;/li&gt;
&lt;li&gt;Added the cors middleware and passed it more specific options for out application, including the origin for frontend requests.&lt;/li&gt;
&lt;li&gt;Applied the express middlewares to our express server, and set the Apollo Server cors to FALSE, meaning that the Apollo cors is disabled, and we are going to be using the cors middleware.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If all goes well, there should be NO http-header errors anymore! &lt;em&gt;But we still don't get any data returned, why is that?&lt;/em&gt; Well, we created a query for &lt;code&gt;users&lt;/code&gt; but we didn't give our Apollo server any &lt;strong&gt;resolvers&lt;/strong&gt; to deal with the query. So far we only have a single query for an individual user.  The final step should be making a resolver for actually fetching all users.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Users Resolver&lt;/strong&gt;
This is pretty simple actually.  First, go to backend/src/schema.graphql and add a &lt;code&gt;users&lt;/code&gt; query to our graphql schema. The Query type should look like this after adding the users:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;
  &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, we added a users query, and that's going to return an array of User objects.&lt;/p&gt;

&lt;p&gt;Next, we need to write the logic for the Query, so we head to backend/src/Query.js and create a users query after the user query we already had.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nf"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;users&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a pretty straightforward query due to the fact we are asking for ALL users. We are just accessing the Prisma users() method, made available to us because we passed it into the context object way back when the server was made. So we are accessing the context, then out Prisma database (db), then we are accessing the prisma queries, and calling users() with no additional options. (You can pass users() more options, but we just want all users).&lt;/p&gt;

&lt;h2&gt;
  
  
  Query Done!
&lt;/h2&gt;

&lt;p&gt;At this point, (errors fixed and all) you should be able to go to &lt;em&gt;localhost:3000/users&lt;/em&gt; and see logged to the console a data object with all of the users somewhere.  I have what I see below.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fys1bwdcztsyrjsqjnndm.JPG" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fys1bwdcztsyrjsqjnndm.JPG" alt="Output"&gt;&lt;/a&gt;&lt;br&gt;
You can see in the object that's returned, we actually have the users nested under data.users.&lt;/p&gt;

&lt;p&gt;We have the data! But we can clean it up a little.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Query&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;GET_USERS_QUERY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{({&lt;/span&gt;&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="p"&gt;})&lt;/span&gt;
          &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Query&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because we know that data we want is within "data" in the object, we can restructure that, and then further destructure the users within data.  This lets us just access the array of users using "users."  Within the return of the Query component, we can map through the array of users, returning a &lt;/p&gt;
&lt;p&gt; tag with a "key" set to their id (React want's unique keys) and return the users name within the tag. So, if you had 4 users, you would just get a list of them all output to the DOM.  Yay!&lt;/p&gt;

&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;To recap, making a a query involves the following core steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Writing the query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adding the query&lt;/strong&gt; to your GraphQL schema.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Creating a resolver&lt;/strong&gt; to handle the query coming from the client.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hopefully, this is a good intro to basic queries in Apollo and implementing them with our Prisma methods in the resolvers.  Next step, mutations!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>graphql</category>
      <category>react</category>
      <category>apollo</category>
    </item>
    <item>
      <title>Critique My Resume!</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Tue, 16 Apr 2019 01:14:47 +0000</pubDate>
      <link>https://dev.to/doylecodes/critique-my-resume-5g4d</link>
      <guid>https://dev.to/doylecodes/critique-my-resume-5g4d</guid>
      <description>&lt;p&gt;I know there have been some posts in the past where people critique resumes, but I haven't seen one for a while. Are there any long-time devs out there willing to check out my resume and give some tips? Thanks!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://drive.google.com/file/d/1XQ4yDjyd8qPwI9x0LTEAHWT-3Fd5aGDv/view?usp=sharing"&gt;Check it out here as a pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uaLLJybP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/wf4zywidpw3e6dbn923p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uaLLJybP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/wf4zywidpw3e6dbn923p.png" alt="Resume" width="785" height="895"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>career</category>
      <category>beginners</category>
      <category>discuss</category>
      <category>help</category>
    </item>
    <item>
      <title>GraphQL Basics - Part 4: Connecting Frontend and Backend</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Mon, 15 Apr 2019 18:52:11 +0000</pubDate>
      <link>https://dev.to/doylecodes/graphql-basics-part-4-connecting-frontend-and-backend-35p7</link>
      <guid>https://dev.to/doylecodes/graphql-basics-part-4-connecting-frontend-and-backend-35p7</guid>
      <description>&lt;p&gt;For those of you following along, sorry it been nearly a month since the last post in this series! I did start the series having everything already completed and it became evident that I still had some learning to do! Good for learning, bad for regular blog posts. I wrote this post because of all the learning:&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;div class="ltag__link__content"&gt;
    &lt;div class="missing"&gt;
      &lt;h2&gt;Article No Longer Available&lt;/h2&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Let's Get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Ready for the Frontend
&lt;/h2&gt;

&lt;p&gt;Ok. The first thing we need to do is some housekeeping. (If you've been following along with me, we've got everything set up in a single folder. What I am going to be doing now is moving everything to a structure where the current files for the backend are in a "backend" folder while I have a separate "frontend" folder for all of that.&lt;/p&gt;

&lt;p&gt;So, in the root of my project I added a &lt;em&gt;backend&lt;/em&gt; folder and a &lt;em&gt;frontend&lt;/em&gt; folder, then dropped everything that existed into the backend folder. I had to update all the require('') statements accordingly, but in VS Code it all happened automatically for me.&lt;/p&gt;

&lt;p&gt;So now we've got this structure: &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%2Fd4asb93xl8t0xg3ngmdu.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%2Fd4asb93xl8t0xg3ngmdu.png" alt="new folder structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should be able to go into backend/ in your terminal and make sure everything is working still by running &lt;code&gt;nodemon index.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If everything is still good, I like to add a script in my &lt;em&gt;package.json&lt;/em&gt; so I don't have to remember that command. In &lt;em&gt;package.json&lt;/em&gt;, go ahead and add the following code. It will allow you to start up the backend server by typing &lt;code&gt;npm run dev&lt;/code&gt; opposed to the &lt;code&gt;nodemon index.js&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;nodemon index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Frontend with Next.js
&lt;/h2&gt;

&lt;p&gt;For this project I will be using Next.js.  It's a really robust framework that offers a lot of nice things like server-side rendering for React. It's also easy to get started with because it has features like a &lt;em&gt;pages&lt;/em&gt; folder, where all component in that folder become pages you can navigate to.  It also has a nice way to link to other pages that's super easy so it's great for this purpose.&lt;/p&gt;
&lt;h3&gt;
  
  
  Set up Next.js
&lt;/h3&gt;

&lt;p&gt;First, we need to go into our &lt;em&gt;frontend&lt;/em&gt; folder, and we are going to install Next, React, and React DOM. In addition, we also make a folder for our components, the pages, and a lib folder for a high order component.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm init -y
npm install --save react react-dom next
mkdir pages components lib


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

&lt;/div&gt;

&lt;p&gt;With Next installed, we can now do a number of things!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a High Order Component for Apollo to work&lt;/li&gt;
&lt;li&gt;Create a custom _app.js component (Main app that gets passed to the Apollo Client component)&lt;/li&gt;
&lt;li&gt;Create a custom _document.js component (Overrides the normal document creation for server-side rendering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create a High Order Component
&lt;/h3&gt;

&lt;p&gt;First, we need to install a few more things.&lt;/p&gt;

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

npm i --save next-with-apollo apollo-boost


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Next With Apollo:&lt;/strong&gt; This is basically a component that we pass our Apollo Client to which will eventually wrap up our entire application.&lt;br&gt;
&lt;strong&gt;Apollo Boost:&lt;/strong&gt; Apollo Boost is just a package that contains the most-used Apollo client packages.  Essentially there a many individual packages you can use, but most people use a core set, so they have them all as apollo-boost.&lt;/p&gt;

&lt;p&gt;To make the HOC component, I created &lt;em&gt;ApolloHOC.js&lt;/em&gt; in my &lt;em&gt;lib&lt;/em&gt; folder.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;withApollo&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;next-with-apollo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apollo-boost&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`http://localhost:4000`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`http://localhost:4000`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;operation&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;operation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setContext&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;fetchOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;include&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;withApollo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;So, let's walk through the code above.  First we import next-with-apollo and apollo-boost.&lt;/p&gt;

&lt;p&gt;Next we are creating the function createClient, which accepts headers (for SSR) and returns an instance of the Apollo Client.  To that, we pass in the endpoint of our backend (the localhost:4000) as well as set the requests to include the header credentials with all requests, and also pass along those headers.&lt;/p&gt;

&lt;p&gt;Basically, we need to pass the headers along with all requests (this is something happening from next-with-apollo) and also set credential to "include" so our app could do authentication if we wanted to. Overkill for this tutorial, but a good starting place for other projects.&lt;/p&gt;

&lt;p&gt;Finally, we export the HOC &lt;code&gt;withApollo&lt;/code&gt; that we require from next-with-apollo, passing in out Apollo Client.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create our custom _app.js
&lt;/h3&gt;

&lt;p&gt;Next, we need to create a custom _app.js file in out pages directory.  This is pretty well documented in the &lt;a href="https://nextjs.org/docs/#custom-app" rel="noopener noreferrer"&gt;Next.js docs&lt;/a&gt; but it essentially is where we wrap up our entire app with the withApollo component to expose our entire frontend to the Apollo Client. My custom _app.js is as follows.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;next/app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-apollo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;withApollo&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../lib/ApolloHOC&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyApp&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;getInitialProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;pageProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getInitialProps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;pageProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInitialProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;pageProps&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;apollo&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Container&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ApolloProvider&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;apollo&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;pageProps&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ApolloProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Container&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;withApollo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Basically, the only difference between mine (above) and the example provided in the Next.js docs is that I also destructure &lt;code&gt;apollo&lt;/code&gt; from the props and that gets put in the ApolloProvider as props.  I don't actually remember where I found these examples, but the docs for the &lt;a href="https://www.apollographql.com/docs/react/api/react-apollo#ApolloProvider" rel="noopener noreferrer"&gt;Apollo Provider explains wrapping your app&lt;/a&gt;. Alright, so now our components should have access to the Apollo Client!&lt;/p&gt;

&lt;h3&gt;
  
  
  Create custom _document.js
&lt;/h3&gt;

&lt;p&gt;Another thing that I do is create a &lt;a href="https://nextjs.org/docs/#custom-document" rel="noopener noreferrer"&gt;custom _document.js&lt;/a&gt;. The custom document is to &lt;em&gt;"Is used to change the initial server-side rendered document markup"&lt;/em&gt;.  Basically, I mostly use this to hook up Styled Components, but it seems like for server-side rendering it has a lot of uses. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Document&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Head&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NextScript&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;next/document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ServerStyleSheet&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyDocument&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Document&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;getInitialProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;renderPage&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ServerStyleSheet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;renderPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectStyles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;))&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;styleTags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getStyleElement&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;styleTags&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;styleTags&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Head&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;NextScript&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



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

&lt;/div&gt;

&lt;p&gt;I got his custom _document.js from the &lt;a href="https://github.com/zeit/next.js/blob/master/examples/with-styled-components/pages/_document.js" rel="noopener noreferrer"&gt;Next.js Examples with Styled Components&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A Few more Installs
&lt;/h3&gt;

&lt;p&gt;If you try and start everything up right now, you'll get some errors due to some peer dependencies going on. I also have &lt;code&gt;styled-components&lt;/code&gt; required in the &lt;em&gt;_document.js&lt;/em&gt; so, let's install the following:&lt;/p&gt;


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

&lt;p&gt;npm i --save styled-components graphql react-apollo&lt;/p&gt;

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

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Basic Pages&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;To get ready for making out first graphQL query &amp;amp; mutation, we'll need a few basic pages.  Go ahead and create the files &lt;em&gt;addItem&lt;/em&gt; and &lt;em&gt;viewItems&lt;/em&gt; in your pages directory and put in the following:&lt;/p&gt;

&lt;h4&gt;
  
  
  addItem.js
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Add&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="nx"&gt;will&lt;/span&gt; &lt;span class="nx"&gt;go&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;};&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;addItem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;/p&gt;

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

&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  viewItems.js&lt;br&gt;
&lt;/h4&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;viewItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;br&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Items&lt;/span&gt; &lt;span class="nx"&gt;will&lt;/span&gt; &lt;span class="nx"&gt;show&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;br&gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;};&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;viewItems&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;/p&gt;

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

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Check That Everything Works!&lt;br&gt;
&lt;/h3&gt;

&lt;p&gt;Ok, before checking that everything works, I will (same as the backend) go to my &lt;em&gt;package.json&lt;/em&gt; in the frontend and add the script &lt;code&gt;"dev":"next"&lt;/code&gt; and that will allow me to just type in &lt;code&gt;npm run dev&lt;/code&gt; to start up the frontend.&lt;/p&gt;

&lt;p&gt;You can now run &lt;code&gt;npm run dev&lt;/code&gt; within the frontend &lt;em&gt;and&lt;/em&gt; backend directories and be up and running! You should be able to navigate to &lt;strong&gt;localhost:3000/addItem&lt;/strong&gt; to see "Add item form will go here" from our paragraph tag in the &lt;code&gt;addItem.js&lt;/code&gt; file, and similarly for to &lt;strong&gt;localhost:3000/viewItems&lt;/strong&gt; to see "Items will show here!".&lt;/p&gt;

&lt;h2&gt;
  
  
  All Set Up!
&lt;/h2&gt;

&lt;p&gt;Hopefully, everything should be good to go now!  In the next post, I'll look at creating a GraphQL Query!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>graphql</category>
      <category>react</category>
    </item>
    <item>
      <title>Dealing with Setback (Also, how do you prepare for a blog series?)</title>
      <dc:creator>Ryan Doyle</dc:creator>
      <pubDate>Sat, 06 Apr 2019 19:31:59 +0000</pubDate>
      <link>https://dev.to/doylecodes/dealing-with-setback-also-how-do-you-prepare-for-a-blog-series-38hm</link>
      <guid>https://dev.to/doylecodes/dealing-with-setback-also-how-do-you-prepare-for-a-blog-series-38hm</guid>
      <description>&lt;h2&gt;
  
  
  Error: Weren't You Doing a GraphQl Series?
&lt;/h2&gt;

&lt;p&gt;A month or so I started a series on setting up GraphQL and Prisma with Apollo (Client &amp;amp; Server).  Originally I was going to use a GraphQL Yoga server and just copy what I had done in a tutorial and explain what I learned, but someone suggested using the new Apollo Server 2. So, I went overachiever and decided to do that instead.&lt;/p&gt;

&lt;p&gt;Turns out, I'm learning a ton more than I necessarily thought that I would, which is nice, but it also meant I had to stop that series for a while in the middle of it so I could make sure I &lt;em&gt;actually&lt;/em&gt; knew what I was doing. Most of the problems being around passing authentication/headers/cookies back and fourth and not totally necessary for what I wanted to show, but I felt like I really didn't understand the tooling I was using since I was struggling with that. &lt;/p&gt;

&lt;p&gt;So, first, how do you deal with setbacks? These are some of the things I did to get back on track.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Take a Break&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/eMeMQ0Y4DHS2k/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/eMeMQ0Y4DHS2k/giphy.gif" alt="Break Time" width="250" height="250"&gt;&lt;/a&gt;&lt;br&gt;
This might seem counterintuitive, but taking a break is often what you need. It might be a break completely from the project, or just going and working on something else to get your mind in a new space. It's easy to get your mind stuck in a particular space. Sometimes we are focused on solving a problem a particular way and when you take a break you have a realization it might be something else, which leads you to look in a new direction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Read Documentation&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/c5aFcAbGCFz3y/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/c5aFcAbGCFz3y/giphy.gif" alt="Reading" width="399" height="225"&gt;&lt;/a&gt;&lt;br&gt;
Sometimes, especially when you are new to a tool/framework/whatever, you just need to read the documentation in &lt;em&gt;detail&lt;/em&gt;. For example, when trying to use a middleware to set up CORS between my servers I thought I had set it all up right, but kept getting the dreaded error that I didn't have the correct headers. After about an hour of trying all sorts of things, deep in the docs I find that my server has this all set up already, and it was overriding my more specific options from my middleware.  That was causing the problem, and one line of &lt;code&gt;cores: false,&lt;/code&gt; solved the problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Take a Step Back&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/fZ3XnLKTOHI9W/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/fZ3XnLKTOHI9W/giphy.gif" alt="Kidding" width="200" height="240"&gt;&lt;/a&gt;&lt;br&gt;
Don't assume everything you've done is working. I think often we get caught up in thinking, "Iv'e done this thing x way before, so i'll implement it x way this time and it'll work great!" The problem is, maybe it won't work great and something you assume is working is causing a problem that leads you to think something else is an issue. Sometimes I will just go back to the beginning (or back to the start of whatever is the problem) and just start logging things out or testing smaller pieces to make sure everything is as expected.  It can help limit your focus to what the real problem is.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does Everyone Prepare A Series?
&lt;/h2&gt;

&lt;p&gt;Now that (as of today) I seem to have life in Apollo land all sorted out and I can start working on continuing my series on it, it got me thinking, &lt;strong&gt;How do people usually start a blog series?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I think in a perfect world you would have everything written out ahead of time, but that seems to be large time commitment that I don't really have at the moment.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Question
&lt;/h2&gt;

&lt;p&gt;If you have ever wrote a series of posts, how do you go about writing it, and if you have setbacks in the middle, what do you do about it?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>tutorial</category>
      <category>javascript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
