<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Segun98</title>
    <description>The latest articles on Forem by Segun98 (@segun98).</description>
    <link>https://forem.com/segun98</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%2F459421%2F5bbcb1d1-aa49-481a-90f2-a2c2bb39f495.jpeg</url>
      <title>Forem: Segun98</title>
      <link>https://forem.com/segun98</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/segun98"/>
    <language>en</language>
    <item>
      <title>Simple Password Reset Flow using Nodejs, Expressjs, SendGrid and uuid</title>
      <dc:creator>Segun98</dc:creator>
      <pubDate>Mon, 01 Feb 2021 18:55:41 +0000</pubDate>
      <link>https://forem.com/segun98/simple-password-reset-flow-using-nodejs-expressjs-sendgrid-and-uuid-1ihl</link>
      <guid>https://forem.com/segun98/simple-password-reset-flow-using-nodejs-expressjs-sendgrid-and-uuid-1ihl</guid>
      <description>&lt;p&gt;I implemented a password reset flow in a personal project and I thought I should write about it. This article assumes you can set up an express server, query a database, create routes... and all that fun stuff.&lt;/p&gt;

&lt;p&gt;Packages we'd use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SendGrid (for emails) - npm i @sendgrid/mail
Knex (A Database Query Builder. Of course you can use any) - npm i pg knex
uuid (to generate unique ids) - npm i uuid
bcrypt (to hash passwords) - npm i bcryptjs

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

&lt;/div&gt;



&lt;p&gt;Go ahead and install them!&lt;/p&gt;

&lt;h3&gt;
  
  
  First I'd explain the process:
&lt;/h3&gt;

&lt;h5&gt;
  
  
  Step 1:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Create a 'password_reset' table in your database with columns "id", "email".&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 2:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Users submit their email requesting for a password change, we check if this email exists in our "users" table (existing users table). If the user exists, we insert a unique id and the submitted email into the "password_reset" table and send them an email with a link containing that id.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 3:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;We use the id in the link to verify the user and update with the newly entered password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Easy stuff! Now let's write some code.&lt;br&gt;
&lt;/p&gt;

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

//imports

const knex = require("--your db setup--")
//sendgrid for emails
const sgMail = require('@sendgrid/mail');
//uuid
const {
    v4: uuid
} = require("uuid")

//add your api key. Please sign up on https://sendgrid.com to get yours
sgMail.setApiKey(--Your API key--);

router.post("/password_reset", async (req, res)=&amp;gt; {
         //email user submitted

        const {
            email
        } = req.body

        try {
            //check if user exists

            const user = await knex("users").select("email").where({
                email
            })

            if (user.length &amp;gt; 0) {
            //generate a unique id

                let id = uuid()

            //insert into the "password_reset" table

                await knex("password_reset").insert([{
                    id,
                    email: user[0].email
                }])

            //email content sent with SendGrid. The unique id is sent in the email as a link

                const content = {
                    to: email,
                    from: "support@me.com",
                    subject: "Password Recovery",
                    html: `&amp;lt;body&amp;gt;
                    &amp;lt;p&amp;gt;Click to set a new password : &amp;lt;a href="yoururl/password/reset/${id}"&amp;gt;Reset password&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;

                    &amp;lt;/body&amp;gt;`
                }
                await sgMail.send(content)
                return res.send("Please check your email for the next step")
            }

          //if email doesn't exist

            return res.status(404).send("email does not exist in our records")
        } catch (error) {
            res.send(error.message)
        })

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

&lt;/div&gt;



&lt;p&gt;Next step is to verify the user by checking the "password_reset" table with the id passed in the email url.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#### Step 3A

  router.get("/verify_email/:id", async (req, res) =&amp;gt; {
       //pass in the id as a parameter

        const {
            id
        } = req.params

        try {
           //query for the email with the provided id

            const email = await knex("password_reset").select("email").where({
                id
            })
           //send back the email

           return res.send(email[0])

        } catch (error) {
            res.status(404).send(error.message)
        }
}
)

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

&lt;/div&gt;



&lt;p&gt;Finally We update the user's password in the "users" table, and clear the record in the "password_reset" table to ensure the link sent in the email in "Step 2" is useless.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##### Step 3B:

router.post("/change_password", async(req,res)=&amp;gt;{
        const {
            email,
            id,
            newpassword
        } = req.body

        try {
            //final check if user exists in "password_reset" table

            const user = await knex("password_reset").select("email").where({
                email
            })
            if (user.length === 0) {
                return res.status(404).send("an error occured")
            }

            //hash new password

            const salt = await bcrypt.genSalt(10)
            const hashedpassword = await bcrypt.hash(newpassword, salt)

           //update the users table!

            await knex('users')
                .where({
                    email
                })
                .update({
                    password: hashedpassword
                })

            //clear the record in "password_reset" table for security

            await knex('password_reset')
                .where({
                    id
                })
                .del()

            return res.send("password successfully changed!")
        } catch (error) {
            res.send(error.message)
        }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The End!&lt;/p&gt;

&lt;h3&gt;
  
  
  Note:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;There are probably other ways to do this, this is what I came up with. &lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Password reset flow with Nodejs, Expressjs and SendGrid Email</title>
      <dc:creator>Segun98</dc:creator>
      <pubDate>Fri, 22 Jan 2021 11:17:43 +0000</pubDate>
      <link>https://forem.com/segun98/password-reset-flow-with-nodejs-expressjs-and-sendgrid-email-8i2</link>
      <guid>https://forem.com/segun98/password-reset-flow-with-nodejs-expressjs-and-sendgrid-email-8i2</guid>
      <description>&lt;p&gt;I implemented a password reset flow in a personal project and I thought I should write about it. This article assumes you can set up an express server, query a database, create routes... and all that fun stuff.&lt;/p&gt;

&lt;p&gt;Packages we'd use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SendGrid (for emails) - npm i @sendgrid/mail
Knex (A Database Query Builder. Of course you can use any) - npm i pg knex
uuid (to generate unique ids) - npm i uuid
bcrypt (to hash passwords) - npm i bcryptjs

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

&lt;/div&gt;



&lt;p&gt;Go ahead and install them!&lt;/p&gt;

&lt;h3&gt;
  
  
  First I'd explain the process:
&lt;/h3&gt;

&lt;h5&gt;
  
  
  Step 1:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Create a 'password_reset' table in your database with columns "id", "email".&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 2:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Users submit their email requesting for a password change, we check if this email exists in our "users" table (existing users table). If the user exists, we insert a unique id and the submitted email into the "password_reset" table and send them an email with a link containing that id.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 3:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;We use the id in the link to verify the user and update with the newly entered password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Easy stuff! Now let's write some code.&lt;br&gt;
&lt;/p&gt;

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

//imports

const knex = require("--your db setup--")
//sendgrid for emails
const sgMail = require('@sendgrid/mail');
//uuid
const {
    v4: uuid
} = require("uuid")

//add your api key. Please sign up on https://sendgrid.com to get yours
sgMail.setApiKey(--Your API key--);

router.post("/password_reset", async (req, res)=&amp;gt; {
         //email user submitted

        const {
            email
        } = req.body

        try {
            //check if user exists

            const user = await knex("users").select("email").where({
                email
            })

            if (user.length &amp;gt; 0) {
            //generate a unique id

                let id = uuid()

            //insert into the "password_reset" table

                await knex("password_reset").insert([{
                    id,
                    email: user[0].email
                }])

            //email content sent with SendGrid. The unique id is sent in the email as a link

                const content = {
                    to: email,
                    from: "support@me.com",
                    subject: "Password Recovery",
                    html: `&amp;lt;body&amp;gt;
                    &amp;lt;p&amp;gt;Click to set a new password : &amp;lt;a href="yoururl/password/reset/${id}"&amp;gt;Reset password&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;

                    &amp;lt;/body&amp;gt;`
                }
                await sgMail.send(content)
                return res.send("Please check your email for the next step")
            }

          //if email doesn't exist

            return res.status(404).send("email does not exist in our records")
        } catch (error) {
            res.send(error.message)
        })

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

&lt;/div&gt;



&lt;p&gt;Next step is to verify the user by checking the "password_reset" table with the id passed in the email url.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#### Step 3A

  router.get("/verify_email/:id", async (req, res) =&amp;gt; {
       //pass in the id as a parameter

        const {
            id
        } = req.params

        try {
           //query for the email with the provided id

            const email = await knex("password_reset").select("email").where({
                id
            })
           //send back the email

           return res.send(email[0])

        } catch (error) {
            res.status(404).send(error.message)
        }
}
)

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

&lt;/div&gt;



&lt;p&gt;Finally We update the user's password in the "users" table, and clear the record in the "password_reset" table to ensure the link sent in the email in "Step 2" is useless.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;##### Step 3B:

router.post("/change_password", async(req,res)=&amp;gt;{
        const {
            email,
            id,
            newpassword
        } = req.body

        try {
            //final check if user exists in "password_reset" table

            const user = await knex("password_reset").select("email").where({
                email
            })
            if (user.length === 0) {
                return res.status(404).send("an error occured")
            }

            //hash new password

            const salt = await bcrypt.genSalt(10)
            const hashedpassword = await bcrypt.hash(newpassword, salt)

           //update the users table!

            await knex('users')
                .where({
                    email
                })
                .update({
                    password: hashedpassword
                })

            //clear the record in "password_reset" table for security

            await knex('password_reset')
                .where({
                    id
                })
                .del()

            return res.send("password successfully changed!")
        } catch (error) {
            res.send(error.message)
        }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The End!&lt;/p&gt;

&lt;h3&gt;
  
  
  Note:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;There are probably other ways to do this, this is what I came up with. &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>passwordflow</category>
    </item>
    <item>
      <title>Front End Web Development Today - A Guide For Absolute Beginners</title>
      <dc:creator>Segun98</dc:creator>
      <pubDate>Tue, 01 Sep 2020 01:04:57 +0000</pubDate>
      <link>https://forem.com/segun98/front-end-web-development-today-a-guide-for-absolute-beginners-apj</link>
      <guid>https://forem.com/segun98/front-end-web-development-today-a-guide-for-absolute-beginners-apj</guid>
      <description>&lt;p&gt;Front end Web development is a huge deal today, as websites have become more complex. Developers have to be concerned about Accessibility, User experience and User Interface Design, Performance, SEO and so on. &lt;/p&gt;

&lt;p&gt;This is a straight forward guide for absolute beginners who may be confused with what to learn or making a choice of what technology to use. &lt;/p&gt;

&lt;p&gt;HTML, CSS and Vanilla Javascript are what every front end developer should start with, before thinking about the shiny frameworks. HTML defines the structure of a web page, CSS adds styling and Javascript adds functionality. &lt;/p&gt;

&lt;p&gt;Note that the following are my opinion, they are what I think wouldn't be overwhelming for a beginner.&lt;/p&gt;

&lt;p&gt;A few important things to learn in:&lt;/p&gt;

&lt;p&gt;HTML&lt;/p&gt;

&lt;p&gt;• Syntax&lt;/p&gt;

&lt;p&gt;• Basic Tags&lt;/p&gt;

&lt;p&gt;• Forms&lt;/p&gt;

&lt;p&gt;• SEO&lt;/p&gt;

&lt;p&gt;• Best Practices&lt;/p&gt;

&lt;p&gt;CSS&lt;/p&gt;

&lt;p&gt;• Syntax&lt;/p&gt;

&lt;p&gt;• Positioning&lt;/p&gt;

&lt;p&gt;• Box Model&lt;/p&gt;

&lt;p&gt;• Flex and Grid&lt;/p&gt;

&lt;p&gt;• Animation&lt;/p&gt;

&lt;p&gt;• Responsive Design &lt;/p&gt;

&lt;p&gt;• Media Queries&lt;/p&gt;

&lt;p&gt;• Best Practices&lt;/p&gt;

&lt;p&gt;Vanilla Javascript &lt;/p&gt;

&lt;p&gt;• DOM manipulation&lt;/p&gt;

&lt;p&gt;• Syntax&lt;/p&gt;

&lt;p&gt;• Functions&lt;/p&gt;

&lt;p&gt;• Arrays and Objects&lt;/p&gt;

&lt;p&gt;• Loops&lt;/p&gt;

&lt;p&gt;Learning technologies is by building with them, watching tutorials alone can be quite deceptive. &lt;/p&gt;

&lt;p&gt;Some beginner friendly channels on Youtube :  Dev Ed, Traversy Media and NetNinja. &lt;/p&gt;

&lt;p&gt;After a few projects highlighting all these technologies, you can proceed to picking a framework. &lt;/p&gt;

&lt;p&gt;Project Ideas &lt;/p&gt;

&lt;p&gt;• Clone websites of your choice&lt;/p&gt;

&lt;p&gt;• Todolist&lt;/p&gt;

&lt;p&gt;• A small game&lt;/p&gt;

&lt;p&gt;There are three popular frameworks/libraries for front end web development and you can pick any of them after you do your research: Angular, Reactjs and Vuejs. On the websites of these frameworks, there are guides on what to understand in Javascript before learning them. Do well to follow their advice. &lt;/p&gt;

&lt;p&gt;Happy Learning!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>frontend</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>Query GraphQL API In Nextjs Data Fetching Methods - GetServerSideProps</title>
      <dc:creator>Segun98</dc:creator>
      <pubDate>Fri, 28 Aug 2020 00:12:15 +0000</pubDate>
      <link>https://forem.com/segun98/query-graphql-api-in-nextjs-data-fetching-methods-getserversideprops-km8</link>
      <guid>https://forem.com/segun98/query-graphql-api-in-nextjs-data-fetching-methods-getserversideprops-km8</guid>
      <description>&lt;p&gt;The logical tool to use when I set out to build this website - &lt;a href="https://locallog.now.sh"&gt;Locallog&lt;/a&gt; was Nextjs, I needed SEO amongst other things that a single page app did not provide and also, Nextjs is awesome.&lt;/p&gt;

&lt;p&gt;I used an Express server with MongoDB on the backend. It was the first time I was using a GraphQL API.  The popular tool I saw everywhere to query a GraphQL API on the front end was Apollo so I went straight to Nextjs’s Github page and looked up the Apollo example, I copied the entire code without checking the README. Querying the API worked, but I ran into issues because I didn’t query inside of Nextjs’s data fetching methods. If you are not familiar with them, check out the Docs.  &lt;/p&gt;

&lt;p&gt;My data wasn’t fetching at request time so it did not populate the head tag and I was getting a blank screen at some point. The whole idea of using Nextjs for SEO was defeated. I raised an issue on Github and was told to use a lighter library. I consulted Google and found a library: GraphQL Request, it is a Minimal GraphQL client supporting Node and browsers for scripts or simple apps &lt;/p&gt;

&lt;p&gt;I will be showing you how to query and make mutations using variables. We will be building a Todo app.  &lt;/p&gt;

&lt;p&gt;First, install the library on npm (you can also use Yarn) and import ‘request’ on your page like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Npm i ‘graphql-request’ // in terminal  


import { request } from "graphql-request"; // in your page


We will be constructing our query like so:  



//request query
  const TODOS = ` {  
    todos{  
     id  
     name  
     completed  
     date  
    }  
   }`;


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

&lt;/div&gt;



&lt;p&gt;Here, we query for all Todo items. First we created a variable and assigned it to our request query.  &lt;/p&gt;

&lt;p&gt;Now we would use it inside of Nextjs’ getServerSideProps, you could use getStaticProps or combine getStaticProps with getStaticPaths, read the docs on Nextjs.org.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function getServerSideProps() {  
    //'request' from ‘graphql-request’ library 
    const res = await request(‘/api/graphiql’, TODOS);  
    const data = res.todos;  

    return {  
     props: {  
      data //Pass Data in props  
      },  
     };  
    }  
    //pass data into component  
    function Index({ data }) {  
     return (  
        &amp;lt;div&amp;gt; 
      ...use data here  
        {data.id}  
        &amp;lt;/div&amp;gt;  
     )  
    };


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

&lt;/div&gt;



&lt;p&gt;It’s that simple, we passed in two arguments in &lt;code&gt;request(‘/api/graphql’,TODOS)&lt;/code&gt;. &lt;code&gt;‘/api/graphiql’&lt;/code&gt; is our request endpoint and &lt;code&gt;‘TODOS’&lt;/code&gt; is the variable assigned to our query.&lt;br&gt;
&lt;/p&gt;

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


import { request } from"graphql-request";

const TODOS = `{  
 todos{  
    id  
    name  
    completed  
    date  
  }  
 }  
`;  

export async function getServerSideProps(){  
 const res = await request(‘/api/graphql’,TODOS);  
 const data = res.todos;  

 return {  
 props: {  
   data
  },  
 };  
}  

function Index({ data }) {  
 return (  
      &amp;lt;div&amp;gt;  
      {data.id}  
      &amp;lt;/div&amp;gt;  
 )  
}; 

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

&lt;/div&gt;



&lt;p&gt;Now Let's query for a single Todo Item&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const TODO = `
query todo($id: String!) { // First line  
 todo(id: $id){ // Second line  
    name  
    date  
  }  
 }  
`;

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

&lt;/div&gt;



&lt;p&gt;First Line:&lt;code&gt;“$id”&lt;/code&gt;here is a variable and it is a GraphQL “STRING” type (click Here to learn about all GraphQL types), the exclamation mark stands for ‘Non Null’  &lt;/p&gt;

&lt;p&gt;Second Line: We are then assigning the variable to the argument we would pass into our request.  &lt;/p&gt;

&lt;p&gt;Notice we only returned ‘name’ and ‘date’ from our query, excluding ’completed’. Graphql helps prevent over-fetching.  &lt;/p&gt;

&lt;p&gt;Now let’s use it in graphql-request.  &lt;/p&gt;

&lt;p&gt;Create a page in pages folder like so: ‘/pages/[id].js’, this allows us pass in our parameter in the request. If you are unfamiliar with this check out  Docs .&lt;br&gt;
&lt;/p&gt;

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

  export async function getServerSideProps({params }) { //Line 1 
    const variables = { // Line 2  
     id: params.id,  
     };  

    const res = await request(‘/api/graphiql’, TODO, variables); // Line 3  
     const data = res.todo;  
      return {  
      props: {  
        data  
      },  
     };  
    } 

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

&lt;/div&gt;



&lt;p&gt;Line 1: we pass in ‘params’ for access to our url parameter  &lt;/p&gt;

&lt;p&gt;Line 2: we created a ‘variables’ object to pass in the expected ‘id’ variable in our request.  &lt;/p&gt;

&lt;p&gt;Line 3: we have a third parameter in our request where we pass in the variables.  &lt;/p&gt;

&lt;p&gt;Now we can display a single todo item in our page.&lt;br&gt;
&lt;/p&gt;

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

 const TODO = `  
  query todo($id:String!) { // First line  
   todo(id:$id) { // Second line  
        name  
        date  
   }  
   }  
  `
  export async function getServerSideProps({params }) {//Line 1  
   const variables = { // Line 2  
    id: params.id 
   };  

   const res = await request(‘/api/graphiql’, TODO, variables); // Line 3  
   const data = res.todo;  
   return {  
   props: {  
      data  
    },  
   };  
  }  

  function TodoPage({data}){  
   return(  
   … 
   )  
  };

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

&lt;/div&gt;



&lt;p&gt;We will now be making a mutation. We do not need to use a data fetching method because we are not fetching data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
  const ADD_TODO = `  
   mutation addTodo( //Line One  
          $name:String!  
          $date:String  
          $completed:Boolean!)
           {  
        addPost(  
          name: $name  
          date:$date  
          completed:$completed)
           {  
          name //Line Two  
      }  
    } `

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

&lt;/div&gt;



&lt;p&gt;Line One: notice the ‘mutation’ keyword  &lt;/p&gt;

&lt;p&gt;Line Two: we can also return data from a mutation  &lt;/p&gt;

&lt;p&gt;Using our mutation query in the component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  function  Component () {  
    const[name, setName ] = React.useState("") //input state  

    function addTodo(e) { //submit function  
     e.preventDefault() 

    const variables = {  
          name, //from input state  
          date: new Date(),  
          completed: false  
     };

     try{  
     const res = await request("api/graphql", ADD_TODO, variables);   
     console.log(res.data)  
    } catch(err) {  
     console.log(err.message)  
    }  
  }   

    return (  
      &amp;lt;div&amp;gt;  
      …  
      &amp;lt;/div&amp;gt;  
    )  
  };


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

&lt;/div&gt;



&lt;p&gt;Done! I am glad you completed this. This is my first technical post, please excuse the mistakes or better still leave a comment.  &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
