<?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: Yuvraj Dagur</title>
    <description>The latest articles on DEV Community by Yuvraj Dagur (@thatfreakcoder).</description>
    <link>https://dev.to/thatfreakcoder</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%2F529584%2F49fd6065-4b74-46b9-a233-251a05ecc50f.jpeg</url>
      <title>DEV Community: Yuvraj Dagur</title>
      <link>https://dev.to/thatfreakcoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thatfreakcoder"/>
    <language>en</language>
    <item>
      <title>Creating a GraphQL API. A Code Tutorial for complete beginners.</title>
      <dc:creator>Yuvraj Dagur</dc:creator>
      <pubDate>Fri, 21 Jan 2022 14:09:01 +0000</pubDate>
      <link>https://dev.to/thatfreakcoder/creating-a-graphql-api-a-code-tutorial-for-complete-beginners-3l53</link>
      <guid>https://dev.to/thatfreakcoder/creating-a-graphql-api-a-code-tutorial-for-complete-beginners-3l53</guid>
      <description>&lt;p&gt;Recently, &lt;strong&gt;&lt;a href="https://graphql.org/" rel="noopener noreferrer"&gt;GraphQL&lt;/a&gt;&lt;/strong&gt; has made a lot of buzz among the developers community, and it has been seeing a lot of attention because of the dynamicness and lot less redundant data fetching capabilities it packs under its hood. In this Code Tutorial, we will get to learn about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what GraphQL really is, why has it created such a hype amongst new age developers? &lt;/li&gt;
&lt;li&gt;How is it different from the REST approach, and finally &lt;/li&gt;
&lt;li&gt;We will be building our own API with GraphQL along with Code Tutorials.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So let's get into it 👨🏻‍💻&lt;/p&gt;




&lt;h2&gt;
  
  
  #1. What is GraphQL? A quick primer
&lt;/h2&gt;

&lt;p&gt;Before understanding what GraphQL is, let’s first understand what &lt;strong&gt;Query Languages&lt;/strong&gt; are. Query Languages are languages that request the data from a database (called queries) to a client side application through a server. A well known example is &lt;strong&gt;Structured Query Language, or SQL&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%2F6og4gurhofg752yfcmxd.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%2F6og4gurhofg752yfcmxd.gif" alt="simpson-dictionary-reading"&gt;&lt;/a&gt;&lt;br&gt;
Coming to GraphQL, by definition - &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“GraphQL is an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data” (&lt;a href="https://en.wikipedia.org/wiki/GraphQL" rel="noopener noreferrer"&gt;source: wiki&lt;/a&gt;). &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But the question remains the same. What exactly is GraphQL? Simply put, GraphQL is a new age Query Language developed by Facebook that helps Application Programming Interfaces (APIs) fetch only that data which is request by the client, and nothing else, thus enormously reducing the redundant data at the API endpoint and making the requests blazing fast and developer friendly. &lt;/p&gt;

&lt;p&gt;But, wasn’t that already being done by RESTful APIs 🤔? The answer is yes, but GraphQL is different (and also advantageous) than REST in a lot of ways. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GraphQL is Client-Driven, whereas REST is Server Driven.&lt;/li&gt;
&lt;li&gt;Queries are organized in terms of Schema and strict typecasting in GraphQL, whereas REST has Endpoints for that task.&lt;/li&gt;
&lt;li&gt;GraphQL calls Specific data with single call. REST calls Fixed data with multiple calls.&lt;/li&gt;
&lt;li&gt;Instead of the GET, POST, PUT, DELETE operations in REST, GraphQL has Query, Mutation and Subscription for data manipulation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we know the “What”s and “Where”s of GraphQL, let’s dive straight into our favorite part. The Development 🤓.&lt;/p&gt;


&lt;h2&gt;
  
  
  #2. Let’s Play with GraphQL
&lt;/h2&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%2Fi9fr8auh3k7v78mz6myf.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%2Fi9fr8auh3k7v78mz6myf.gif" alt="rolling-dev"&gt;&lt;/a&gt;&lt;br&gt;
In this section, we will learn about a step-by-step procedure of building an API using GraphQL and Express on top of Node.js. In the next section, we will be implementing these prerequisites into code and start our development for the API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Prerequisites&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understanding of GraphQL&lt;/li&gt;
&lt;li&gt;Node Package Manager (or NPM) with version 10+&lt;/li&gt;
&lt;li&gt;Knowledge of basic querying and server-side programming.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will be needing a Database to store the user data and everything else that a client side application can request for. For this, we will be using 📁 &lt;a href="https://www.npmjs.com/package/lowdb" rel="noopener noreferrer"&gt;LowDB&lt;/a&gt;, which is a &lt;em&gt;simple file-based JSON database for small projects in the localhost&lt;/em&gt;. Then we will be needing a middleware to connect our database system to the requesting frontend application. For this, we will be using the &lt;a href="https://www.npmjs.com/package/express" rel="noopener noreferrer"&gt;Express&lt;/a&gt; middleware with the GraphQL implementation of Express - the &lt;a href="https://www.npmjs.com/package/graphql-express" rel="noopener noreferrer"&gt;graphql-express&lt;/a&gt; library. Finally, we will be making a client side application using &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; which can request all the data from the local database and can perform operations on the database like Read, Write and Delete.&lt;/p&gt;

&lt;p&gt;So our roadmap is pretty simple and straightforward 🛣️. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Create a Database Schema &amp;gt; Use a middleware server to query the database &amp;gt; Create a frontend application to use the data. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If this is too much at once for you, do not worry as this is article is being written kept in mind that the reader is a first timer for GraphQL and basic querying as usual.&lt;/p&gt;

&lt;p&gt;With that being done, let’s dive into the &lt;code&gt;CODE&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  #3. Setting up Express GraphQL
&lt;/h2&gt;

&lt;p&gt;Let’s begin with the basic project structure of a Node.js application. Begin a new project in a new folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;graphql-example
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;graphql-example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use NPM to intiialize a project&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Install the required dependencies for Express, MongoDB (Mongoose) and some additional dependencies required for the function of Express.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install express mongoose body-parser cors --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apollo Server is a community-maintained open-source GraphQL server that works with all Node.js HTTP server frameworks, so next we are going to download and save that.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This should’ve created a package.json and a package-lock.json file within your folder. These files contains the information regarding our environment, the dependencies and the specific versions to run those dependencies.&lt;br&gt;
This means our environment is ready and we can now start developing the integrated server and API. We are going to write the Schema inside the index.js file.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;index.js&lt;/code&gt; file, start off by writing this code.&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="nx"&gt;mongoose&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;mongoose&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;schema&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;./schema&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;bodyParser&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;body-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;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="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="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mongodb://localhost:27017/moviesdb&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;connect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mongoose&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;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;useNewUrlParser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nx"&gt;connect&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;db&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Connected correctly to server!&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="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="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;err&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;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="na"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;schema&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="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolvers&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="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;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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="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="nf"&gt;cors&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In line number 1 to 6, we’re implementing the necessary modules. Note that here we have imported the ./schema, but we haven’t created that yet. We will be doing this in the next step. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In line number 9 to 14, we are connecting the project to the mongoDB database and logging any error we face to the console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In line number 16 to 19, we’re creating a new Apollo Server with &lt;code&gt;typeDefs&lt;/code&gt;and &lt;code&gt;Resolver&lt;/code&gt;. We’ll be defining those in the ./schema later in this tutorial.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In line 21 to 26, we’re firing up the Express Server at port 4000, when we can actually be able to interact with what we’re building.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;GraphQL has two main principles in order to work: &lt;code&gt;types&lt;/code&gt; and &lt;code&gt;resolvers&lt;/code&gt;. We defined them in Apollo Server. We’ll import them from the file we’ll create later.&lt;/p&gt;

&lt;p&gt;For the time being, let’s create the file &lt;code&gt;models/movie.js&lt;/code&gt; that’ll contain the movie-Mongoose model.&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;mongoose&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;mongoose&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;Schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Schema&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;movieSchema&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;Schema&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="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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;rating&lt;/span&gt;&lt;span class="p"&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="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;producer&lt;/span&gt;&lt;span class="p"&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="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;timestamps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;Movies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Movie&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;movieSchema&lt;/span&gt;&lt;span class="p"&gt;);&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="nx"&gt;Movies&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;movieSchema&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’re going to build a simple movie app, where we can show, add, edit, and delete movies. That way we’ll get through the basics of GraphQL, which is the main goal of this article.&lt;/p&gt;

&lt;p&gt;In lines 4 to 19, we’re basically determining the schema of the database that is going to hold the data of movies. Every movie is going to have a Name and a Producer of type String and a Rating of type Number. &lt;/p&gt;

&lt;h2&gt;
  
  
  #4. Designing the Schema
&lt;/h2&gt;

&lt;p&gt;So now let’s move on to the &lt;code&gt;schema.js&lt;/code&gt; file where we’re going to build our GraphQL API. &lt;br&gt;
Create a new file in the root of the folder by the name of &lt;code&gt;schema.js&lt;/code&gt; and add the following code.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;gql&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="nx"&gt;Movie&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;./models/movie&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;Movies&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="nx"&gt;gql&lt;/span&gt; &lt;span class="s2"&gt;`
   type Movie {
     id: ID!
     name: String!
     producer: String!
     rating: Float!
 }
 type Query {
   getMovies: [Movie]
   getMovie(id: ID!): Movie
 }
 type Mutation {
     addMovie(name: String!, producer: String!, rating: Float!): Movie
     updateMovie(id: ID!, name: String!, producer: String!, rating: Float): Movie
     deleteMovie(id: ID!): Movie
   }
`&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this, we’re building the schema. We defined the Movie type which will have an ID, name of the movie and the producer, and a rating of type Float. The “!” after the types shows that these field are necessary.&lt;/p&gt;

&lt;p&gt;Unlike REST approach of getting different tasks done at different endpoint URLs, GraphQL can create operations in a single endpoint. That is what we have done in line line 11 onwards. The type Query determines the GET operations, and type Mutation determines the modification operations like POST, DELETE, etc. In getMovies, we’re returning a list of all available movies in our database and in getMovie we’re getting the specific movie by the ID of that movie.&lt;/p&gt;

&lt;p&gt;Now we’re going to link these with the Mongoose Database queries that are going to perform the actions in the database. And this is done by Resolvers. Resolvers are functions that connects schema fields and types to various backends. It can read, write and delete data from and to anywhere in the database, be it SQL, NoSQL or Graph based database.&lt;/p&gt;

&lt;p&gt;Here’s how we’re going to implement Resolvers in our code:&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;resolvers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;getMovies&lt;/span&gt;&lt;span class="p"&gt;:&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="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="nx"&gt;Movie&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;


    &lt;span class="na"&gt;getMovie&lt;/span&gt;&lt;span class="p"&gt;:&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="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="nx"&gt;Movie&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findById&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;id&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;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;addMovie&lt;/span&gt;&lt;span class="p"&gt;:&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="o"&gt;=&amp;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;movie&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;Movie&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="nx"&gt;args&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="na"&gt;producer&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;producer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;rating&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;rating&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;movie&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;updateMovie&lt;/span&gt;&lt;span class="p"&gt;:&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="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;args&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="k"&gt;return&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;Movie&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOneAndUpdate&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;args&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="p"&gt;{&lt;/span&gt;
           &lt;span class="na"&gt;$set&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="nx"&gt;args&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="na"&gt;producer&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;producer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="na"&gt;rating&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;rating&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="na"&gt;new&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&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="nx"&gt;Movie&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="s1"&gt;Something went wrong when updating the movie&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="k"&gt;continue&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&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="nx"&gt;typeDefs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;resolvers&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 the basic logic of MongoDB and CRUD application and is not in the scope of explanation of this article since it is majorly focussed on GraphQL. Although the logics are pretty simple and straightforward for anyone to understand so do skim through it once.&lt;/p&gt;

&lt;p&gt;With this, we’re done with a basic Movie API which can perform all the CRUD Operations on a database of movies. To test this out, we’re going to fire up our node server and open the browser in &lt;a href="http://localhost:4000/graphql" rel="noopener noreferrer"&gt;http://localhost:4000/graphql&lt;/a&gt; which will open up the GraphQL Playground.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ node index.js
🚀 Server ready at [http://localhost:4000/graphql](http://localhost:4000/graphql) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the Playground UI opens up, we’re first going to create a Movie Record for the database since it would be empty initially.&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%2Fmiro.medium.com%2Fmax%2F2000%2F1%2ARdWpskRaXHL9tzRSOheFeg.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%2Fmiro.medium.com%2Fmax%2F2000%2F1%2ARdWpskRaXHL9tzRSOheFeg.png" alt="add movie"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now let’s list out all the movies in the database&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%2Fmiro.medium.com%2Fmax%2F2000%2F1%2APOBrL7wymcL7mtZT9tTZlw.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%2Fmiro.medium.com%2Fmax%2F2000%2F1%2APOBrL7wymcL7mtZT9tTZlw.png" alt="view-db"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we have successfully created a Movie API where we can perform all the CRUD operations on a single endpoint, as well as ask for just the data that we want resulting in blazing fast API response and a developer friendly return object that makes development fast and super easy.&lt;/p&gt;

&lt;p&gt;In the next part, we will be using this API in a React Project, along with a brief summary of what we did. &lt;/p&gt;

&lt;p&gt;Till then, you can &lt;a href="https://rzp.io/l/yuvrajdagur" rel="noopener noreferrer"&gt;SUPPORT MY WORK&lt;/a&gt; here. hope you enjoyed. Stay Safe y'all&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Enable Dark Mode in GitHub.</title>
      <dc:creator>Yuvraj Dagur</dc:creator>
      <pubDate>Sun, 20 Dec 2020 14:59:58 +0000</pubDate>
      <link>https://dev.to/thatfreakcoder/how-to-enable-dark-mode-in-github-290a</link>
      <guid>https://dev.to/thatfreakcoder/how-to-enable-dark-mode-in-github-290a</guid>
      <description>&lt;h1&gt;
  
  
  DARK MODE is now available in GitHub.
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VX-Uqvvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qst3htg25xxpq1r4ehll.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VX-Uqvvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qst3htg25xxpq1r4ehll.jpg" alt="github profile"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com"&gt;GitHub&lt;/a&gt; has announced the &lt;strong&gt;Dark Theme&lt;/strong&gt; for GitHub during the &lt;a href="https://githubuniverse.com"&gt;Github Universe&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Yes, finally the long awaited &lt;strong&gt;Dark Mode&lt;/strong&gt; on GitHub is now available to paint your repositories and profiles Dark. &lt;/p&gt;

&lt;p&gt;Here's how you can enable this dark theme for your github. &lt;/p&gt;

&lt;h1&gt;
  
  
  Step 1: Log In to your Github Account
&lt;/h1&gt;

&lt;p&gt;You can skip this step if you're already logged into your GitHub account on your system. If not &lt;a href="https://github.com/login"&gt;Login Here&lt;/a&gt; using username and password.&lt;br&gt;
You will then be redirected to the home page of Github which will look something like this. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dgqbEQCV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/462p3lg2wdz1daxinqhl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dgqbEQCV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/462p3lg2wdz1daxinqhl.png" alt="Github Home Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 2: Open Your Account Page
&lt;/h1&gt;

&lt;p&gt;Once logged in, head over to the dropdown on top right just below your Profile Picture, and click on your username to head over to your profile main page. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hrORjjLC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pps9ovuqy1328xhqd47k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hrORjjLC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pps9ovuqy1328xhqd47k.png" alt="dropdown"&gt;&lt;/a&gt;Ps. You will be redirected to this page. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eNpEQg2o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o2ez8esgfaumfoxmraxd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eNpEQg2o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o2ez8esgfaumfoxmraxd.png" alt="profile page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 3: Toggle &lt;strong&gt;Dark Mode&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;On the Top Right corner, there can be seen a toggle which will &lt;em&gt;paint your repositories dark.&lt;/em&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lb9O2ts2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ivmafasmmtt201ky35l1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lb9O2ts2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ivmafasmmtt201ky35l1.jpg" alt="Light mode"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;before toggling 👆🏻&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;after toggling 👇🏻&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m4KTHbdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/juk09vviex50l0u6o42q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m4KTHbdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/juk09vviex50l0u6o42q.png" alt="dark mode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Enjoy the Dark Themed Github across all devices 🎉
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VX-Uqvvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qst3htg25xxpq1r4ehll.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VX-Uqvvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qst3htg25xxpq1r4ehll.jpg" alt="github profile"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HtgS4L6e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/73s24zsj0yz4pnojqix4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HtgS4L6e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/73s24zsj0yz4pnojqix4.png" alt="repo"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;
Thank you for reading. Do Follow me on my other social media handles 👇🏻. 

&lt;p&gt;~ Yuvraj.&lt;br&gt;
&lt;a href="https://linkedin.com/in/yuvraj-dagur"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://twitter.com/@yuvrajdagur12"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/thatfreakcoder"&gt;GitHub&lt;/a&gt; | &lt;a href="https://yuvraj-dagur.medium.com/"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>tutorial</category>
      <category>darkmode</category>
      <category>git</category>
    </item>
    <item>
      <title>The basics of GitHub and Git Commands for every beginner.</title>
      <dc:creator>Yuvraj Dagur</dc:creator>
      <pubDate>Wed, 09 Dec 2020 19:47:34 +0000</pubDate>
      <link>https://dev.to/thatfreakcoder/the-basics-of-github-and-git-commands-for-every-beginner-5jj</link>
      <guid>https://dev.to/thatfreakcoder/the-basics-of-github-and-git-commands-for-every-beginner-5jj</guid>
      <description>&lt;h2&gt;
  
  
  But Before that, What exactly is Git and GitHub?
&lt;/h2&gt;

&lt;p&gt;Common Definition — &lt;strong&gt;Git&lt;/strong&gt; is a &lt;em&gt;version control system&lt;/em&gt;, that keeps track of all the minute changes in your project and allows you to move back to the previous version irrespective of the number of times you change it. &lt;br&gt;
&lt;strong&gt;GitHub&lt;/strong&gt;, on the other hand, is the most popular service that hosts all your git repositories. And there are plenty of others like Github.&lt;/p&gt;

&lt;p&gt;You can download git for your system depending on your OS from &lt;a href="https://git-scm.com/download"&gt;here&lt;/a&gt;. Also, consider making a GitHub account from &lt;a href="https://github.com"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that you're done with Git and GitHub, let's start with the basic commands you're going to need to keep track of your projects.&lt;/p&gt;
&lt;h1&gt;
  
  
  1. &lt;code&gt;git init&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;git init&lt;/code&gt; is the beginning of any Git Repository. This command initializes an empty git repository in the current working directory. Please note that this repository will be created in the current directory you are working in. Make sure you are in your project folder before initializing a Git Repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git init
Initialized empty Git repository in E:/workingfolder/.git/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can now work in this folder and do the necessary changes in your projects, and keep track of all the changes.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. &lt;code&gt;git clone&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Cloning in git is exactly what it is named. It CLONES or creates a copy of a repository which might be hosted on GitHub or any other git hosting platform.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone &amp;lt;url_of_the_original_github_repository.git&amp;gt;
Cloning into 'project name'...
remote: Enumerating objects: 36, done.
remote: Counting objects: 100% (36/36), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 36 (delta 14), reused 33 (delta 11), pack-reused 0
Receiving objects: 100% (36/36), 13.41 KiB | 259.00 KiB/s, done.
Resolving deltas: 100% (14/14), done.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose you want to use someone else's opensource work, or you want to contribute to their work, you can do that by cloning their repository into your local system and start working.&lt;/p&gt;

&lt;h1&gt;
  
  
  3. &lt;code&gt;git branch&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;git branch&lt;/code&gt; allows you to make a branch or an &lt;em&gt;extension&lt;/em&gt; of the current files in the repository. What is the use, you may ask?&lt;br&gt;
This is typically used in 2 scenerios. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;While working with other's repository and contributing to their code, hence making a &lt;em&gt;pull request&lt;/em&gt;, and.&lt;/li&gt;
&lt;li&gt;Making updates to an already up and running, completed and hosted projects, so that the new changes doesn't affect the main branch and hence break the whole code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To create a new branch, simply run in the current working directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git branch -M &amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, to delete an already existing branch, you can run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git branch -d &amp;lt;branch_name&amp;gt;
Deleted branch &amp;lt;branch_name&amp;gt; (was &amp;lt;branch-id&amp;gt;).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-d&lt;/code&gt; here specifies that you want to delete the mentioned branch, and hence removes all the files and changes of &lt;em&gt;that branch&lt;/em&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  4. &lt;code&gt;git checkout&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Okay, you've created a new branch and are now set to work in the new branch and make updates there. But, you're currently still in the &lt;code&gt;main&lt;/code&gt; branch of your repository. How do you switch branches?&lt;br&gt;
This is where &lt;code&gt;git checkout&lt;/code&gt; comes into play. It simply swaps the current branch to the desired branch you want to work on. &lt;/p&gt;

&lt;p&gt;You can see all the available branches in a repository by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git branch
  branch1
  branch2
* main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the * before &lt;code&gt;* main&lt;/code&gt; depicts that you're currently in the &lt;code&gt;main&lt;/code&gt; branch. Let's say you want to move into &lt;code&gt;branch1&lt;/code&gt;, you can do that by simply running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout branch1
Switched to branch 'branch1'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then you can confirm the switch by running again&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git branch 
* branch1
  branch2
  main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and so now the * is before &lt;code&gt;* branch1&lt;/code&gt; which means that you're now in &lt;code&gt;branch1&lt;/code&gt; branch.&lt;/p&gt;

&lt;h1&gt;
  
  
  5 &lt;code&gt;git status&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Okay, most changes are done and you are up for the day. The next day, you want to know where you left off, what are the changes that you have committed and pushed, and what you haven't. All the changes information will appear in &lt;strong&gt;red&lt;/strong&gt; can be viewed by running the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that &lt;code&gt;git status&lt;/code&gt; gives the status of the current branch, so make sure you are on the right branch. &lt;/p&gt;

&lt;h1&gt;
  
  
  6. &lt;code&gt;git add&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Once you are done modifying or updating your code, you can save the files locally. But these changes and modifications won't be reflected in your Git Repository until you Add them in it. And this is where &lt;code&gt;git add&lt;/code&gt; is used. &lt;/p&gt;

&lt;p&gt;To save the file changes into the Git Repository, or to Add new files to an empty repository, run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the &lt;strong&gt;.&lt;/strong&gt; after &lt;code&gt;git add .&lt;/code&gt; is used to specify that you want to add all the files in the current working directory. If you want to add a specific file, you can do so my mentioning the name of the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git add main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If now you run &lt;code&gt;git status&lt;/code&gt;, you will notice that all the changes now appear in &lt;strong&gt;green&lt;/strong&gt; color, to show that these changes are added to the local repository and are ready to be committed and pushed.&lt;/p&gt;

&lt;h1&gt;
  
  
  7. &lt;code&gt;git commit&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;Changes are added to the repository and now you want to let the repository know what changes have you done and what is their use. You can do this by &lt;strong&gt;committing&lt;/strong&gt; your changes and adding a Commit Message.&lt;br&gt;
To do so, simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git commit -m "Your Commit Message Here"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  8. &lt;code&gt;git remote&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;You have created a Git repository on your local machine. And you have created a Git Repository on a remote git server, say, GitHub. Now You want to connect the local repository to the remote repository so that the changes you commit in this repository can also be committed to the remote repository. This is where &lt;code&gt;git remote&lt;/code&gt; is used.&lt;br&gt;
To connect the remote repo with the local repo, simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote add origin https://github.com/&amp;lt;username&amp;gt;/&amp;lt;repository_name&amp;gt;.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  9. &lt;code&gt;git push&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;The final step of the git operation is to push your code to the remote server where your Git Repository is hosted, be it GitHub, GitLab or any other for that matter. &lt;br&gt;
You can do this with a simple command of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push origin &amp;lt;you_branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or, if it your first push (to the main branch)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and this will upload your code to the remote repository and you are good to go.&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;
This is all about the basic git commands you need to know to get started with Git and Github and manage your code with this amazing version control tool. 

&lt;p&gt;Thank you for reading. &lt;br&gt;
~ Yuvraj.&lt;br&gt;
&lt;a href="https://linkedin.com/in/yuvraj-dagur"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://twitter.com/@yuvrajdagur12"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/thatfreakcoder"&gt;GitHub&lt;/a&gt; | &lt;a href="https://yuvraj-dagur.medium.com/"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>opensource</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Just received my #HacktoberFest Badge</title>
      <dc:creator>Yuvraj Dagur</dc:creator>
      <pubDate>Fri, 04 Dec 2020 07:25:51 +0000</pubDate>
      <link>https://dev.to/thatfreakcoder/just-received-my-hacktoberfest-badge-1nb9</link>
      <guid>https://dev.to/thatfreakcoder/just-received-my-hacktoberfest-badge-1nb9</guid>
      <description>&lt;p&gt;Just received my &lt;strong&gt;#HacktoberFest&lt;/strong&gt; Badge on DEV. I completed my Hacktober Fest journey at the very end of October, barely making it through. &lt;/p&gt;

&lt;p&gt;My last PR was accepted just 3 days before the fest ends. And then the dreadful 14 day review period kept me waiting. &lt;br&gt;
But finally I have received my Badge now. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/thatfreakcoder/"&gt;My GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/thatfreakcoder"&gt;DEV&lt;/a&gt;&lt;/p&gt;

</description>
      <category>hacktoberfest</category>
      <category>firstpost</category>
    </item>
  </channel>
</rss>
