<?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: Akuagwu Philemon</title>
    <description>The latest articles on Forem by Akuagwu Philemon (@philzace1).</description>
    <link>https://forem.com/philzace1</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%2F503871%2F6d63f1b6-25d3-4928-82dd-548761671ce3.jpeg</url>
      <title>Forem: Akuagwu Philemon</title>
      <link>https://forem.com/philzace1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/philzace1"/>
    <language>en</language>
    <item>
      <title>Getting Started with React, Fauna and URQL</title>
      <dc:creator>Akuagwu Philemon</dc:creator>
      <pubDate>Tue, 27 Apr 2021 23:06:30 +0000</pubDate>
      <link>https://forem.com/philzace1/getting-started-with-react-fauna-and-urql-2nep</link>
      <guid>https://forem.com/philzace1/getting-started-with-react-fauna-and-urql-2nep</guid>
      <description>&lt;p&gt;Written in connection with the &lt;a href="https://fauna.com/blog/write-with-fauna"&gt;Write with Fauna&lt;/a&gt; program.&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Using a Todo Application &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YUf4raQR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://paper-attachments.dropbox.com/s_8231CF08A85B0FE28CD2F8D398A749D0CF1EDC596D8C13E603936BD0B48CA2A0_1606081752014_ezgif.com-gif-maker.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YUf4raQR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://paper-attachments.dropbox.com/s_8231CF08A85B0FE28CD2F8D398A749D0CF1EDC596D8C13E603936BD0B48CA2A0_1606081752014_ezgif.com-gif-maker.gif" alt="Gif of the app we are migrating to Fauna"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What we will be building
&lt;/h2&gt;

&lt;p&gt;I feel the best way to learn is by doing. In this article to we will build a Todo app using URQL, &lt;br&gt;
we will learn how to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setup URQL with React &lt;/li&gt;
&lt;li&gt;Setting Fetch Options like “request headers”&lt;/li&gt;
&lt;li&gt;Write queries &lt;/li&gt;
&lt;li&gt;Write Mutation&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What is  URQL
&lt;/h2&gt;

&lt;p&gt;URQL stands for Universal React Query Library. URQL is a GraphQL client that exposes a set of React components and hooks. It's built to be highly customizable and versatile so you can take it from getting started with your first GraphQL project all the way to building complex apps and experimenting with GraphQL clients. Please Note that we weill make use of Git , Redux , GraphQL,  NodeJS and Reactstrap but we are going to concentrate fully on URQL.&lt;br&gt;
You can get the finished project - &lt;a href="https://github.com/PhilzAce1/urql-react-todo-app"&gt;URQL_TODO_APP&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisite for the article
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic Knowledge of React&lt;/li&gt;
&lt;li&gt;Basic Graphql knowledge &lt;/li&gt;
&lt;li&gt;NodeJS Installed on your PC&lt;/li&gt;
&lt;li&gt;Knowledge of Redux will be a plus (as we will be using redux for state management)&lt;/li&gt;
&lt;li&gt;Git &amp;amp; GitHub knowledge&lt;/li&gt;
&lt;li&gt;Basic Knowledge of Redux&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Since we will be making use of the Fauna GraphQL API. Make sure you Sign up to &lt;a href="https://fauna.com/"&gt;Fauna&lt;/a&gt; and set up your GraphQL API. Fauna GraphQL api requires an authorization  key which we will save as an Environment variable (for Security reason). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; &lt;br&gt;
In the root level of your react application, create a file &lt;code&gt;.env.local&lt;/code&gt; . In this file, add an entry for the generated key:&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;REACT_APP_FAUNA_SECRET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;fnAD7S71UlACBcBWehe5q06JQeDRNgJUiNTbvUoN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The file should be named  &lt;code&gt;.env.local&lt;/code&gt;  and not just &lt;code&gt;.env&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Environment Variables that would be used in  a react application should start with “REACT_APP_”… else they won’t be imported by default&lt;/li&gt;
&lt;li&gt;make sure  you also have a &lt;code&gt;.gitignore&lt;/code&gt; file in your project’s root directory that contains &lt;code&gt;.env.local&lt;/code&gt; so that your secrets won’t be added to your git repo and shared with others.&lt;/li&gt;
&lt;li&gt;You’ll have to explicitly stop and restart your application with &lt;code&gt;yarn start&lt;/code&gt; in order to see these changes take.
##
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; &lt;br&gt;
Install relevant packages: &lt;br&gt;
Using Yarn&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;yarn add urql graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or Using npm&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;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt;  urql graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the &lt;code&gt;index.js&lt;/code&gt; file in the root level of the application to 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="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;ReactDOM&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-dom&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&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;App&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;./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;createClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Provider&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;urql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a Urql graphql client&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="nx"&gt;createClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;url&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://graphql.fauna.com/graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;/// the graqhql api url&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="c1"&gt;// fetch options  you which to add&lt;/span&gt;
        &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// request header&lt;/span&gt;
          &lt;span class="c1"&gt;// authorization token imported from .env.local&lt;/span&gt;
          &lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &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;REACT_APP_FAUNA_SECRET&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;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&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;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="nx"&gt;client&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;App&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;/Provider&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;/React.StrictMode&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt;      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code Explanation: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;createClient&lt;/code&gt; - Create a GraphQL client to enable interaction with the GraphQL api&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fetchOptions&lt;/code&gt; - This option allows us to customize the options that will be passed to &lt;code&gt;fetch&lt;/code&gt; when a request is sent to the given API &lt;code&gt;url&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Provider&lt;/code&gt; - A Wrapper component that enables every other component inside it to make use of GraphQL queries that will be sent to our API&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;url&lt;/code&gt; - the GraphQL API url&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;headers&lt;/code&gt; - custom headers needed by the API , this might be needed for Authentication, Authorization, e.t.c.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have been following along so far, congratulations, you are ready to start writing queries and Mutations&lt;/p&gt;

&lt;h2&gt;
  
  
  CRUD (Create, Read, Update, Delete) Operations With URQL
&lt;/h2&gt;

&lt;p&gt;After you setup URQL, the next step is to Create a todo task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create Task&lt;/strong&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useMutation&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;urql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="cm"&gt;/*At the top of your of your file */&lt;/span&gt;
    &lt;span class="c1"&gt;// ...code&lt;/span&gt;

    &lt;span class="cm"&gt;/* Inside a React component */&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CreateTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="cm"&gt;/* GraphQL */&lt;/span&gt; &lt;span class="s2"&gt;`
        mutation($data: TodoInput!) {
          createTodo(data: $data) {
            _id
            name
            completed
          }
        }
      `&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;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createTodoItem&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CreateTodo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


     &lt;span class="kd"&gt;function&lt;/span&gt;  &lt;span class="nx"&gt;onSumbit&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;newItem&lt;/span&gt; &lt;span class="o"&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="na"&gt;name&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;completed&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="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="nx"&gt;createTodoItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newItem&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&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="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;createTodo&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;result&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;addItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;createTodo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// passing data our redux store&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;Code Explanation: &lt;br&gt;
For a better understanding of the code I suggest you go through the &lt;a href="https://github.com/PhilzAce1/urql-react-todo-app"&gt;The Project Repo&lt;/a&gt;, Navigate to &lt;code&gt;src/components/itemModal.js&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;CreateTodo&lt;/code&gt; - is a GraphQL mutation. You can use the GraphQL playground and Schema to structure your mutations and queries.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useMutation&lt;/code&gt; - is imported from &lt;code&gt;urql&lt;/code&gt; and is used to execute GraphQL mutations. it return a tuple.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;result&lt;/code&gt; - The first item in the tuple contains &lt;code&gt;fetching&lt;/code&gt;,  &lt;code&gt;error&lt;/code&gt;,  and &lt;code&gt;data&lt;/code&gt; — it's identical since this is a common pattern of how &lt;code&gt;urql&lt;/code&gt; presents &lt;a href="https://formidable.com/open-source/urql/docs/api/core/#operationresult"&gt;operation results&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;createTodoItem&lt;/code&gt; - The second Item in the tuple is a function where you pass graphQL variables.  Notice in the GraphQL mutation we passed &lt;code&gt;$data&lt;/code&gt; as a variable, and in the &lt;code&gt;createTodoItem&lt;/code&gt; function we passed data as an argument in the function call.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Get All tasks (GET)&lt;/strong&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useQuery&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;urql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="cm"&gt;/*At the top of your of your file */&lt;/span&gt;
    &lt;span class="c1"&gt;// ...code&lt;/span&gt;

    &lt;span class="cm"&gt;/* Inside a React component */&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;result&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useQuery&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="s2"&gt;`
        {
          allTodos {
            data {
              _id
              name
              completed
            }
          }
        }
      `&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;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fetching&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code Explanation: &lt;br&gt;
For a better understanding of the code I suggest you go through the &lt;a href="https://github.com/PhilzAce1/urql-react-todo-app"&gt;The Project Repo&lt;/a&gt;, Navigate to &lt;code&gt;src/components/TodoList.js&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useQuery&lt;/code&gt; - Is used to make GraphQL query request. Similar to the &lt;code&gt;useMutation&lt;/code&gt; hook, the &lt;code&gt;useQuery&lt;/code&gt; hook returns a tuple but with only one Item, which is the result (response) of the query. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;result&lt;/code&gt; -  is the response data from a query request, it is an object with three properties, 

&lt;ul&gt;
&lt;li&gt;data&lt;/li&gt;
&lt;li&gt;fetching&lt;/li&gt;
&lt;li&gt;error&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;data&lt;/code&gt; - basically response data from the server&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fetching&lt;/code&gt; - This is the state of the request, It is initially false, when a request is completed it updates to &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;error&lt;/code&gt; - This propertty contains the error message if any error occurs, it is initially &lt;code&gt;undefined&lt;/code&gt; but updates to an error message from the server if an error occurs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Mark as Completed (Update)&lt;/strong&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useMutation&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;urql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="cm"&gt;/*At the top of your of your file */&lt;/span&gt;
    &lt;span class="c1"&gt;// ...code&lt;/span&gt;

    &lt;span class="cm"&gt;/* Inside a React component */&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;updateTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="cm"&gt;/* GraphQL */&lt;/span&gt; &lt;span class="s2"&gt;`
      mutation UpdateTodo($id: ID!, $data: TodoInput!) {
        updateTodo(id: $id, data: $data) {
          _id
          name
          completed
        }
      }
    `&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;updateResult&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;updateTodoItem&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;updateTodo&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;newItem&lt;/span&gt; &lt;span class="o"&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;props&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="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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="na"&gt;completed&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;completed&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;updateTodoItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newItem&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&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;// result here is similar to  updateResult (first item returned by useMutation)&lt;/span&gt;
      &lt;span class="kd"&gt;const&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;updateTodo&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;result&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;Code Explanation: &lt;br&gt;
For a better understanding of the code I suggest you go through the &lt;a href="https://github.com/PhilzAce1/urql-react-todo-app"&gt;The Project Repo&lt;/a&gt;, Navigate to &lt;code&gt;src/components/updateItemModal.js&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;UpdateTodo&lt;/code&gt; - is a GraphQL mutation. You can use the GraphQL playground and Schema to structure your mutations and queries.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useMutation&lt;/code&gt; - is imported from &lt;code&gt;urql&lt;/code&gt; and is used to execute GraphQL mutations. it return a tuple.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;result&lt;/code&gt;  and &lt;code&gt;updateResult&lt;/code&gt; - The first item in the tuple contains &lt;code&gt;fetching&lt;/code&gt;,  &lt;code&gt;error&lt;/code&gt;,  and &lt;code&gt;data&lt;/code&gt; — it's identical since this is a common pattern of how &lt;code&gt;urql&lt;/code&gt; presents &lt;a href="https://formidable.com/open-source/urql/docs/api/core/#operationresult"&gt;operation results&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;updateTodoItem&lt;/code&gt; - The second Item in the tuple is a function where you pass graphQL variables.  Notice in the GraphQL mutation we passed &lt;code&gt;$id&lt;/code&gt; and &lt;code&gt;$data&lt;/code&gt; as  variables, and in the &lt;code&gt;updateTodoItem&lt;/code&gt; function we passed them  as arguments in the function call.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Delete tasks (DELETE)&lt;/strong&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useMutation&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;urql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="cm"&gt;/*At the top of your of your file */&lt;/span&gt;
    &lt;span class="c1"&gt;// ...code&lt;/span&gt;


    &lt;span class="cm"&gt;/* Inside a React component */&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deleteTodo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="cm"&gt;/* GraphQL */&lt;/span&gt; &lt;span class="s2"&gt;`
      mutation DeleteTodo($id: ID!) {
        deleteTodo(id: $id) {
          _id
          name
        }
      }
    `&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;deleteTask&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;deleteTodo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="nx"&gt;deleteTask&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="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;result&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="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="na"&gt;deleteTodo&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;deletedDataId&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;=&lt;/span&gt; &lt;span class="nx"&gt;result&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;For a better understanding of the code I suggest you go through the &lt;a href="https://github.com/PhilzAce1/urql-react-todo-app"&gt;The Project Repo&lt;/a&gt;, Navigate to &lt;code&gt;src/components/DeleteButton.js&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;deleteTodo&lt;/code&gt; - is a GraphQL mutation. You can use the GraphQL playground and Schema to structure your mutations and queries.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useMutation&lt;/code&gt; - is imported from &lt;code&gt;urql&lt;/code&gt; and is used to execute GraphQL mutations. it return a tuple.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;result&lt;/code&gt;    - The first item in the tuple contains &lt;code&gt;fetching&lt;/code&gt;,  &lt;code&gt;error&lt;/code&gt;,  and &lt;code&gt;data&lt;/code&gt; — it's identical since this is a common pattern of how &lt;code&gt;urql&lt;/code&gt; presents &lt;a href="https://formidable.com/open-source/urql/docs/api/core/#operationresult"&gt;operation results&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;deleteTask&lt;/code&gt; - The second Item in the tuple is a function where you pass GraphQL variables.  Notice in the GraphQL mutation we passed &lt;code&gt;$id&lt;/code&gt;   as  a variable, and in the &lt;code&gt;deleteTask&lt;/code&gt; function we passed them  as arguments in the function call.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In this Article we learnt How to Setup URQL with React,  create data, fetch data, update data  and delete data. URQL is a really wonderful library to look into, You can checkout &lt;a href="https://formidable.com/open-source/urql/docs/"&gt;URQL documentation&lt;/a&gt; for more Information.&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
      <category>serverless</category>
      <category>fauna</category>
    </item>
    <item>
      <title>Creating an Inventory desktop Application with React, Apollo (Graphql), AntD, ElectronJS and, Fauna</title>
      <dc:creator>Akuagwu Philemon</dc:creator>
      <pubDate>Wed, 31 Mar 2021 22:25:54 +0000</pubDate>
      <link>https://forem.com/philzace1/creating-an-inventory-desktop-application-with-react-apollo-graphql-antd-electronjs-and-fauna-19o9</link>
      <guid>https://forem.com/philzace1/creating-an-inventory-desktop-application-with-react-apollo-graphql-antd-electronjs-and-fauna-19o9</guid>
      <description>&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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615422359553_fauna-inventory.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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615422359553_fauna-inventory.gif" alt="a display of the inventory application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Authored in connection with the&lt;/em&gt; &lt;a href="https://fauna.com/blog/write-with-fauna" rel="noopener noreferrer"&gt;&lt;em&gt;Write With Fauna&lt;/em&gt;&lt;/a&gt; &lt;em&gt;program.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;This Article will be a walk-through on how to get started with ElectronJS and FaunaDB. We will also be going through some other libraries like ReactJS and AntD. To fully understand this walkthrough I suggest you practice along with and use &lt;a href="https://github.com/PhilzAce1/Inventory-system-electon-app-" rel="noopener noreferrer"&gt;The Completed project as a Guide&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;This Article is targeted at Beginners to ElectronJS and Fauna, a Reader you are expected to know the following &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React JS&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;NodeJS&lt;/li&gt;
&lt;li&gt;Graphql&lt;/li&gt;
&lt;li&gt;Any design Library like Bootstrap / MaterialUI &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What you will Learn
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to Setup an Electron application from Scratch &lt;/li&gt;
&lt;li&gt;How to Use React and electron&lt;/li&gt;
&lt;li&gt;How to connect Your electron application to a Fauna  server using Apollo GraphQL client&lt;/li&gt;
&lt;li&gt;How to perform basic Get, Create and Delete actions on Fauna &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ElectronJS
&lt;/h2&gt;

&lt;p&gt;ElectronJS is a Javascript framework that is used that allows the development of desktop GUI applications using web technologies. It utilizes the Chromium rendering engine and the Node.js runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;why ElectronJS&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Platform&lt;/strong&gt; Support: With ElectronJs you can create GUI desktop applications for multiple operating systems, for example,  Windows 10 and macOS &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write Code once:&lt;/strong&gt;  The same codebase can be used to create both Desktop GUI application and Web applications&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compiling and Building:&lt;/strong&gt; Electrons application can work without a specific runtime being installed, this simply means that you can install and run an electron application on a device without NODEJS ( JavaScript runtime Environment) being installed on it &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility:&lt;/strong&gt; ElectronJS can be used with most web technology Libraries, for Example ReactJS, VueJS, etc. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article,  I will be making use of ReactJS to create an Inventory system&lt;/p&gt;

&lt;h2&gt;
  
  
  Fauna
&lt;/h2&gt;

&lt;p&gt;Fauna is the data API for client-serverless applications. It provides a GraphQL interface and API that supports custom business logic and is integrated with the serverless ecosystem, enabling developers to build and ship faster. It provides a fast, consistent, reliable, and secure infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apollo Client
&lt;/h2&gt;

&lt;p&gt;Apollo Client is a state management tool for JavaScript that enables you to make GraphQL requests and manage data remotely and locally &lt;br&gt;
 Use it to fetch, cache, and modify application data, all while automatically updating your UI. In this article, we will use React Apollo Client to interact with Fauna GraphQL API&lt;br&gt;
Check &lt;a href="https://www.apollographql.com/docs/react/" rel="noopener noreferrer"&gt;Apollo Docs&lt;/a&gt; for more information&lt;/p&gt;
&lt;h2&gt;
  
  
  AntD
&lt;/h2&gt;

&lt;p&gt;Ant-D short for Ant Design is a Design Library that provides High level reusable react components. They provide components such as &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Icons&lt;/li&gt;
&lt;li&gt;Layout components&lt;/li&gt;
&lt;li&gt;Buttons&lt;/li&gt;
&lt;li&gt;Table component &lt;/li&gt;
&lt;li&gt;Modals&lt;/li&gt;
&lt;li&gt;Toasts, etc&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check &lt;a href="https://ant.design/" rel="noopener noreferrer"&gt;Ant Design Documentation&lt;/a&gt; for more information&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Setup React application using “Create React App”&lt;/strong&gt;&lt;br&gt;
Run &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx create-react-app invetory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Setup Electron with react
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;br&gt;
To set up electron we are going to start by installing the Packages necessary for it by running &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn add -D concurrently electron-builder electron wait-on electron-is-dev cross-env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;concurrently - Run multiple commands concurrently. Like &lt;code&gt;npm run watch-js&lt;/code&gt;; in this case, running the react server and electron server simultaneously&lt;/li&gt;
&lt;li&gt;wait-on - a package that allows processes run asynchronously; in this case “awaits” the react server before starting the electron server.&lt;/li&gt;
&lt;li&gt;electron- the electron framework that we will be utilizing &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; &lt;br&gt;
Configure the electron by following these steps :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a file named ‘electron.js’ in the public folder &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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615425867996_image.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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615425867996_image.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the electron.js file copy the following code and paste it&lt;br&gt;
&lt;/p&gt;&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;electron&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;electron&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// import electron package&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="nx"&gt;electron&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="c1"&gt;// assign the electron 'app' method to the app constant&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BrowserWindow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;electron&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BrowserWindow&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;path&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;path&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="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;url&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;isDev&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;electron-is-dev&lt;/span&gt;&lt;span class="dl"&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;mainWindow&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;createWindow&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;mainWindow&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;BrowserWindow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1020&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;720&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nx"&gt;mainWindow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setMenuBarVisibility&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;// display menu&lt;/span&gt;
      &lt;span class="nx"&gt;mainWindow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loadURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nx"&gt;isDev&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="s2"&gt;`file://&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../build/index.html&lt;/span&gt;&lt;span class="dl"&gt;'&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="nx"&gt;mainWindow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;closed&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mainWindow&lt;/span&gt; &lt;span class="o"&gt;=&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="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ready&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createWindow&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;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;window-all-closed&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="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;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;platform&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;darwin&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;quit&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;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;activate&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="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;mainWindow&lt;/span&gt; &lt;span class="o"&gt;===&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="nf"&gt;createWindow&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;ol&gt;
&lt;li&gt;Add the Start script to the package.json file
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"electron-dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"concurrently &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;cross-env BROWSER=none yarn start&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;wait-on http://localhost:3000 &amp;amp;&amp;amp; electron .&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615426441257_image.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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615426441257_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a /dist/builder-effective-config.yaml file 
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615428009062_image.png"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;and populate the file with this configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;    &lt;span class="na"&gt;directories&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;output&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dist&lt;/span&gt;
      &lt;span class="na"&gt;buildResources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;assets&lt;/span&gt;
    &lt;span class="na"&gt;files&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;build/**/*&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;build/**/*&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;node_modules/**/*&lt;/span&gt;
    &lt;span class="na"&gt;extraMetadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;main&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;build/electron/main.js&lt;/span&gt;
    &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;com.example.electron-cra&lt;/span&gt;
    &lt;span class="na"&gt;extends&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;react-cra&lt;/span&gt;
    &lt;span class="na"&gt;electronVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;9.0.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Direct the electron CLI to the ‘electron.js’  file by adding 
  "main": "public/electron.js",&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;in the package.json file&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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615429177803_image.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%2Fpaper-attachments.dropbox.com%2Fs_6E02712F1E789B8E87494429D0311E896DAD12366D6E785640CEE4A571CB72F5_1615429177803_image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, run &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm run electron-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you followed all the steps correctly, you should have your app launched successfully, if you are having troubles, simply clone the &lt;a href="https://github.com/PhilzAce1/Electron-React-Starter" rel="noopener noreferrer"&gt;React-Electron-Stater&lt;/a&gt; repo&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Electron with AntD
&lt;/h2&gt;

&lt;p&gt;As stated earlier in this Article, AntD is the design library used in this project, and setting it with our Electron application is as easy as setting AntD up with react. Follow these steps to do so &lt;br&gt;
&lt;strong&gt;step 1:&lt;/strong&gt; &lt;br&gt;
install the following dependencies&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn add antd @ant-design/icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Step2 :&lt;/strong&gt;&lt;br&gt;
In the src/index.js file, import AntD stylesheet by add “import 'antd/dist/antd.css';” to the top of the file I will not elaborate much on AntD since it is not the main focus of this Article. For more information visit &lt;a href="https://ant.design/" rel="noopener noreferrer"&gt;AntD official doc&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup Apollo
&lt;/h2&gt;

&lt;p&gt;Apollo Client is a GraphQL client used for GraphQL mutations and queries. In this article, we will use it to interact with the Fauna GraphQL API. To set up Apollo with ElectronJS and ReactJS, you should follow the steps below&lt;br&gt;
&lt;strong&gt;step 1:&lt;/strong&gt; &lt;br&gt;
Install the following dependencies &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yarn add @apollo/client @apollo/react-hooks graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Make sure the access key to your Fauna Graphql API is saved in the .env.local file. &lt;/p&gt;

&lt;p&gt;Checkout Migrating a &lt;a href="https://dev.to/philzace1/migrating-a-react-project-from-aws-appsync-to-fauna-4mde"&gt;react project from aws appsync to fauna&lt;/a&gt; to get started with Creating a Fauna GraphQL  API&lt;br&gt;
Note: &lt;br&gt;
Make use of this GraphQL Schema&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="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Inventory&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;product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;!&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# the name of the product&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# count of the product&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# special Id given to a product&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="k"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Query&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;allInventories&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="n"&gt;Inventory&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;p&gt;In the .env.local file, add an entry for the generated key:&lt;br&gt;
The &lt;code&gt;REACT_APP_FAUNA_SECRET=***&lt;/code&gt;&lt;br&gt;
NOTE:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The config file must be named  &lt;code&gt;.env.local&lt;/code&gt; and not just &lt;code&gt;.env&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;React environment variable should start with “REACT_APP_”…&lt;/li&gt;
&lt;li&gt;make sure that you also have a &lt;code&gt;.gitignore&lt;/code&gt; file in your project’s root directory that contains &lt;code&gt;.env.local&lt;/code&gt; so that your secrets won’t be added to your git repo and shared with others.&lt;/li&gt;
&lt;li&gt;You have to restart the react application for changes to take place&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;br&gt;
Now in the &lt;code&gt;src&lt;/code&gt; directory of your application, add a new file named &lt;code&gt;client.js&lt;/code&gt; with the following content:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&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="s2"&gt;@apollo/client&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="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;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://graphql.fauna.com/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;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &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;REACT_APP_FAUNA_SECRET&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="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InMemoryCache&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 code above simply configures Apollo to make requests to our Fauna database. The uri option specifies the base URI of the GraphQL API, the authorization header indicates that we’re connecting to the specific database instance for the provided key that we generated earlier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; &lt;br&gt;
After that, We will replace the code in the &lt;code&gt;index.js&lt;/code&gt; with&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="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;ReactDOM&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-dom&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;@apollo/client&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&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;App&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;./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;client&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;./client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;ReactDOM&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&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;client&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;App&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="err"&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&lt;/span&gt; &lt;span class="err"&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Get Inventory Items
&lt;/h2&gt;

&lt;p&gt;Getting data from the Fauna GraphQL API is easy and it is done using the “useQuery” from apollo/react-hook.&lt;br&gt;
To make a query to a GraphQL API follow these steps: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;step 1:&lt;/strong&gt; &lt;br&gt;
import the following dependencies &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery, gql } from '@apollo/react-hooks';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;useQuery - a react gook that is used to make GraphQL queries&lt;/li&gt;
&lt;li&gt;gql - The &lt;strong&gt;gql&lt;/strong&gt; template literal tag can be used to concisely write a GraphQL query that is parsed into a standard GraphQL AST.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;step 2: Write the query&lt;/strong&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;listInvetoryItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="cm"&gt;/**GRAPHQL */&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
        query {
          allInventories {
            data {
              count
              product
              id
              _id
            }
          }
        }
      `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&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="kd"&gt;const&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="nx"&gt;inventoryData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;listInvetoryItems&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; &lt;br&gt;
Updating the React UI with the data retrieved from Fauna GraphQL query&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;// From List.js line 64 &lt;/span&gt;
    &lt;span class="nf"&gt;useEffect&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;inventoryData&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
          &lt;span class="nx"&gt;inventoryData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allInventories&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="c1"&gt;// validation&lt;/span&gt;
          &lt;span class="nx"&gt;inventoryData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allInventories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="c1"&gt;// validation&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;newData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inventoryData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allInventories&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="nf"&gt;map&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="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="na"&gt;key&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="nx"&gt;_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// required by antD Table to manage the state of a rows on a table&lt;/span&gt;
          &lt;span class="p"&gt;}));&lt;/span&gt;&lt;span class="c1"&gt;// mapping response &lt;/span&gt;
          &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newData&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="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&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;I think we have an error&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;inventoryData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loading&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;useEffect is the hook that manages the side-effects in functional components.&lt;/li&gt;
&lt;li&gt;inventoryData is destructured alias of ‘data’ which is the response of the Fauna graphQL call &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Add Inventory Item
&lt;/h2&gt;

&lt;p&gt;To add Items to our inventory system we are going to make GraphQL mutations making use of the Apollo client useMutaion hook. To do so, follow the steps below &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 :&lt;/strong&gt;&lt;br&gt;
import the following hooks at the top of the file&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { gql, useMutation } from '@apollo/react-hooks';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;useMutation  is an apollo/react-hooks function that is used to make graphQL Mutations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; &lt;br&gt;
Write and structure the GraphQl mutation.&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;addInventoryMutation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="cm"&gt;/** GraphQL mutation */&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
        mutation CreateInventoryItem($data: InventoryInput!) {
          createInventory(data: $data) {
            count
            id
            product
            _id
          }
        }
      `&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;addInventoryMutation - is a const that contains the GraphQL mutation. You can test and structure a mutation using the graphql playground&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; &lt;br&gt;
Call the useMutation hook, passing the graphQL mutation string and options&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;createItem&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;addInventoryMutation&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createInventory&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// destructure data&lt;/span&gt;
          &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;state&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="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;createInventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;createInventory&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="nx"&gt;state&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useMutation&lt;/code&gt; - is imported from &lt;a class="mentioned-user" href="https://dev.to/apollo"&gt;@apollo&lt;/a&gt;/react-hooks and is used to execute graphql mutations &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;createItem&lt;/code&gt; - useMutation hook returns an array of functions and objects, the first element of the array is a function used to make mutations. The arguments passed to the mutation is the variable of the graphql mutation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&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;// List.js line 88&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onOk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&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="nf"&gt;createItem&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&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;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&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="nf"&gt;setIsOpen&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;br&gt;
Please go through the code &lt;a href="https://github.com/PhilzAce1/Inventory-system-electon-app-" rel="noopener noreferrer"&gt;The Completed project as a Guide&lt;/a&gt; To fully understand this Step&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;onOk - is a call back function called when the form in the modal is submitted &lt;/li&gt;
&lt;li&gt;createItem is the function (first element of the array) returned by the &lt;code&gt;useMutation&lt;/code&gt; hook&lt;/li&gt;
&lt;li&gt;setIsOpen - is a function used to toggle the form Modal display&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Delete Inventory Items
&lt;/h2&gt;

&lt;p&gt;To delete inventory Items follow the steps below&lt;br&gt;
&lt;strong&gt;Step 1 :&lt;/strong&gt;&lt;br&gt;
import the following hooks at the top of the file&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { gql, useMutation } from '@apollo/react-hooks';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;useMutation  is an apollo/react-hooks function that is used to make graphQL Mutations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; &lt;br&gt;
Write and structure the GraphQl mutation.&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;deleteInventoryMutation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="cm"&gt;/** GraphQL delete Mutation */&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
        mutation DeleteInventoryItem($id: ID!) {
          deleteInventory(id: $id) {
            count
            id
            product
            _id
          }
        }
      `&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;deleteInventoryMutation- is a const that contains the graphql mutation. You can test and structure a mutation using the graphql playground&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; &lt;br&gt;
Call the useMutation hook, passing the graphQL mutation string and options&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;deleteItem&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;deleteInventoryMutation&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="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;state&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;x&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;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;deleteInventory&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useMutation&lt;/code&gt; - is imported from &lt;a class="mentioned-user" href="https://dev.to/apollo"&gt;@apollo&lt;/a&gt;/react-hooks and is used to execute graphql mutations &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;deleteItem&lt;/code&gt; - useMutation hook returns an array of functions and objects, the first element of the array is a function used to make mutations. The arguments passed to the mutation is the variable of the graphql mutation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&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;// List.js line 96&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;onDelete&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="nx"&gt;toDel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;del&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;deleteItem&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;variables&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;del&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation: &lt;br&gt;
Please go through the code &lt;a href="https://github.com/PhilzAce1/Inventory-system-electon-app-" rel="noopener noreferrer"&gt;The Completed project as a Guide&lt;/a&gt; To fully understand this Step&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;toDel - is an Array of all selected rows in a table &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we learned how to set up Electron JS, Apollo,  ReactJS, and Fauna, We also learned how to make mutations and queries using Apollo. After this walkthrough article, I am confident that you can start creating your desktop applications using ElectronJS, react, and Fauna. Contact me on &lt;a href="https://twitter.com/philzace1" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; for more information.&lt;/p&gt;

</description>
      <category>fauna</category>
      <category>react</category>
      <category>graphql</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Migrating a React project from AWS Appsync to Fauna</title>
      <dc:creator>Akuagwu Philemon</dc:creator>
      <pubDate>Sat, 05 Dec 2020 23:27:09 +0000</pubDate>
      <link>https://forem.com/philzace1/migrating-a-react-project-from-aws-appsync-to-fauna-4mde</link>
      <guid>https://forem.com/philzace1/migrating-a-react-project-from-aws-appsync-to-fauna-4mde</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;In 2020, there is a variety of technology stack that can be utilized to create a website, and sometimes a developer may require to migrate an already existing project from one tech stack to another. In this article we are going to migrate an AWS Serverless (Appsync)&lt;/p&gt;

&lt;p&gt;Graphql application to a Fauna Graphql Application.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The application we are Migrating&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8tB0yoJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/205d9acf-851c-4f61-8156-2ee6e7943224" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8tB0yoJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/205d9acf-851c-4f61-8156-2ee6e7943224" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Ng8m7jO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/3eefc868-39e2-4cdd-bb92-34252a02728b" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Ng8m7jO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/3eefc868-39e2-4cdd-bb92-34252a02728b" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The application is a “todo application” that uses AWS DynamoDB as its Database and AWS Appsync service currently. We are going to convert the current application to a Fauna application.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Fauna&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://fauna.com/"&gt;Fauna&lt;/a&gt; is a serverless database that provides you with CRUD capabilities and abstract a lot of “Under the hood” processes You might want to use Fauna because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fauna is fast and scales well&lt;/li&gt;
&lt;li&gt;Fauna is relatively easy for beginners to get started with&lt;/li&gt;
&lt;li&gt;The current project rely on two AWS services (Appsync and DynamoDB) but with Fauna it will rely on one&lt;/li&gt;
&lt;li&gt;Fauna currently uses the &lt;a href="https://fauna.com/blog/distributed-consistency-at-scale-spanner-vs-calvin"&gt;&lt;/a&gt; &lt;a href="https://fauna.com/blog/distributed-consistency-at-scale-spanner-vs-calvin"&gt;Calvin&lt;/a&gt; protocol to maintain several full and consistent copies of the data, these data are called &lt;em&gt;replicas,&lt;/em&gt; with the ability to both read and write on every node.&lt;/li&gt;
&lt;li&gt;The learning curve for Fauna is relatively less than learning AWS appsync&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisite for the Article&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic Knowledge of React&lt;/li&gt;
&lt;li&gt;Basic Graphql knowledge&lt;/li&gt;
&lt;li&gt;Using Apollo with React&lt;/li&gt;
&lt;li&gt;NodeJS Installed on your PC&lt;/li&gt;
&lt;li&gt;Knowledge of Redux will be a plus (as we will be using redux for state management)&lt;/li&gt;
&lt;li&gt;Git &amp;amp; GitHub knowledge&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Getting Started&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To Get Started and follow along do the following :&lt;/p&gt;

&lt;p&gt;Clone the repo from GitHub by running the following command in your git bash terminal&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;git clone https://github.com/PhilzAce1/FaunaDB-Todo-app.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git checkout to branch “ready-amplify”&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;git checkout ready-amplify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install all dependencies required to make the application work&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;yarn &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly for your application to work You will have to setup the Appsync service using Amplify or on the Amazon console&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Overview of the Current application&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XihZdJ20--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/1c01a21d-de6d-4102-8648-c546d810c8b0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XihZdJ20--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/1c01a21d-de6d-4102-8648-c546d810c8b0" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Current Application makes use of the “Aws-amplify” package as the GraphQL client, we are going to be making mutations and queries using the Aws Appsync package&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Graphql Client setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Schema&lt;/strong&gt;&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="c"&gt;# Todo -&amp;gt; GraphQL type&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Todo&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;!&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;#title of the task&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;#task completed&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="c"&gt;# Graphql query type -&amp;gt; Specify Queries you want to make available&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Query&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;allTodos&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="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;!]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;#return all Tasks created&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;# fetch tasks by the value of their "completed property&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="n"&gt;todosByCompletedFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;!):&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;!&lt;/span&gt;&lt;span class="err"&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;h2&gt;
  
  
  &lt;strong&gt;Setting up Fauna&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Setting up Fauna is very easy and I am going to walk you through from scratch :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Go to the Fauna website &lt;a href="https://fauna.com/"&gt;Fauna&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;if you have an account, you can log in, if you do not have an account, simply create one&lt;/p&gt;

&lt;p&gt;Creating an account is really easy and straightforward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a new Database&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NNmgiPEW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/5c0103d0-ecc6-448a-ae48-2c6beb8fdb62" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NNmgiPEW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/5c0103d0-ecc6-448a-ae48-2c6beb8fdb62" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Give the Database a name.&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jA5egnha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/dd4fc6e1-f621-418e-be28-beab27fa6cb9" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jA5egnha--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/dd4fc6e1-f621-418e-be28-beab27fa6cb9" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WCnQOf9Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/3d13d852-167a-46e2-a54d-300961e5bb9a" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WCnQOf9Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/3d13d852-167a-46e2-a54d-300961e5bb9a" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this Step, I will compare an AWS Appsync Graphql Schema with a Fauna Schema&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ujh6wO74--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/a6946dff-0c29-4f4b-a5de-53ce391ac4b5" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ujh6wO74--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/a6946dff-0c29-4f4b-a5de-53ce391ac4b5" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the right-hand side we have the AWS Appsync schema, the “@model” directive will create a CRUD resolver for the “Todo” Graphql Type,&lt;/p&gt;

&lt;p&gt;Similarly on the Left Fauna will automatically Create Resolvers based on the schema, you need not provide “directives”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Import the GraphQL schema that you created&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e8k_0k4y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/af10be29-8453-4132-bfe8-a4d2fbdc9106" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e8k_0k4y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/af10be29-8453-4132-bfe8-a4d2fbdc9106" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After importing the Graphql schema, you will be routed to a Graphql playground where you can test and create queries and mutations. Click on the “Docs” tab in the sidebar to check out the available queries and mutations.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Provisioning a New Database Key&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;After you create and configure your database you need a way for client applications to access it.&lt;/p&gt;

&lt;p&gt;The key generated will be used to specify and authenticate our Fauna database. It will also help us access the database to perform, create, read, update, and delete activities from the Client (React) application. Note that authentication and authorization are topics on their own .&lt;/p&gt;

&lt;p&gt;The application key generated has a set of permissions that are grouped together in a “role”.&lt;/p&gt;

&lt;p&gt;We begin by defining the role that has the necessary CRUD operations on tasks&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click on the “Security” tab and then the “New key” button&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ov9Pl-rj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/e29e4bcd-a635-4658-b77d-5698ea5b91ce" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ov9Pl-rj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/e29e4bcd-a635-4658-b77d-5698ea5b91ce" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, there are two roles, “admin” and “server”. We could use these roles for our key, but it is not a good idea because they provide authorization for “Database level operations” such as creating a new collection or even deleting the database itself.&lt;br&gt;
In that case, create a “Custom role”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qEHldDhW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/80acaa64-db5e-4bb1-a89b-77afc74a1c70" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qEHldDhW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/80acaa64-db5e-4bb1-a89b-77afc74a1c70" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you click on the “New Custom role” button&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Select permissions and then save&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZcWqpMtx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/ebcac864-4f7c-4b2d-9a87-8ea7aef3af68" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZcWqpMtx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/ebcac864-4f7c-4b2d-9a87-8ea7aef3af68" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After you save the new Role. You will be able to access it when you want to create a new Key&lt;/p&gt;

&lt;p&gt;Simply create a new Key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qcf03cfw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/abae9f5f-ee2e-4e72-af2e-c1da16422d80" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qcf03cfw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/abae9f5f-ee2e-4e72-af2e-c1da16422d80" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zMfhHMyF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/15a73b02-30b0-431d-93f4-e5a96d09793c" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zMfhHMyF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/15a73b02-30b0-431d-93f4-e5a96d09793c" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the access key that will be used to authenticate your connection with the Fauna database you created.&lt;/p&gt;

&lt;p&gt;For security reasons, we are going to load the Key from a “.env.local" file which is in the root level of your react application.&lt;/p&gt;

&lt;p&gt;In this file, add an entry for the generated key:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;REACT_APP_FAUNA_SECRET=**fnAD7S71UlACBcBWehe5q06JQeDRNgJUiNTbvUoN**&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;NOTE:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The name of the file should be &lt;code&gt;.env.local&lt;/code&gt; and not just &lt;code&gt;.env&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Environment Variables that should be used by a react application should start with “REACT_APP_”…&lt;/li&gt;
&lt;li&gt;make sure that you also have a &lt;code&gt;.gitignore&lt;/code&gt; file in your project’s root directory that contains &lt;code&gt;.env.local&lt;/code&gt; so that your secrets won’t be added to your git repo and shared with others.&lt;/li&gt;
&lt;li&gt;You’ll have to explicitly stop and restart your application with &lt;code&gt;yarn start&lt;/code&gt; in order to see these changes take place.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Connecting React to Fauna&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With AWS Appsync we simply made use of the “aws-amplify” package to interact with the graphql api. But with Fauna we are going to be making use of &lt;a href="https://www.apollographql.com/"&gt;&lt;/a&gt; &lt;a href="https://www.apollographql.com/"&gt;Apollo client&lt;/a&gt;&lt;span&gt;.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;To install the relevant Apollo packages we’ll need, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add @apollo/client graphql @apollo/react-hooks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in your &lt;code&gt;src&lt;/code&gt; directory of your application, add a new file named &lt;code&gt;client.js&lt;/code&gt; with the following content:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&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="s2"&gt;@apollo/client&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="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="nx"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://graphql.fauna.com/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;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="na"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Bearer &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;REACT_APP_FAUNA_SECRET&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="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&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;What the code is doing here is simply configuring Apollo to make requests to our Fauna database. Specifically, the uri makes the request to Fauna itself, then the authorization header indicates that we’re connecting to the specific database instance for the provided key that we generated earlier.&lt;/p&gt;

&lt;p&gt;Note: The authorization header contains the key with the “CustomRole” role (the role we created earlier), and is currently hardcoded to use the same header &lt;em&gt;regardless of which user is looking at our application.&lt;/em&gt; The tasks created by a user will not be specific to that user.&lt;/p&gt;

&lt;p&gt;After that, We will replace the code in the &lt;code&gt;index.js&lt;/code&gt; with&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="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;ReactDOM&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-dom&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;@apollo/client&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&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;App&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;./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;client&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;./client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&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;client&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;App&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="err"&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&lt;/span&gt; &lt;span class="err"&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s compare the AWS Appsync configuration with the Apollo configuration in the &lt;code&gt;index.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LN8d2Boy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/a8e353df-c201-4285-a8cb-73a1bc00dd9f" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LN8d2Boy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/a8e353df-c201-4285-a8cb-73a1bc00dd9f" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the left, you can see the configuration for the AWS Appsync and on the right, we have the configuration for Apollo.&lt;/p&gt;

&lt;p&gt;You can test your app by running &lt;code&gt;Yarn start&lt;/code&gt; if everything still works&lt;/p&gt;

&lt;p&gt;Congratulations You are a rock star&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Migrating CRUD operations&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The next thing you have to do is to Migrate the CRUD operations. Since it is a Todo application, we are going to be creating tasks, marking them as completed, getting already created tasks and finally deleting them Using Fauna and React-Apollo client. We will Compare Appsync and Fauna Mutations and queries&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding tasks to the Todo App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MdmUeYyA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/e97f6849-e25a-40ae-861e-9488d502fcbd" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MdmUeYyA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/e97f6849-e25a-40ae-861e-9488d502fcbd" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;On the Left hand (Appsync) , Notice the structure of the mutation. The &lt;code&gt;API&lt;/code&gt; and &lt;code&gt;graphqlOperation&lt;/code&gt; functions are imported from &lt;code&gt;aws-amplify&lt;/code&gt; package.&lt;/p&gt;

&lt;p&gt;On the Right-hand (Apollo),&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useMutation&lt;/code&gt; - is imported from @apollo/react-hooks and is used to execute graphql mutations&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gql&lt;/code&gt; - is imported from “graphql-tag” package that we installed initially and it’s needed when making graphql api calls with Apollo&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;createItem&lt;/code&gt; - useMutation hook returns an array of functions and objects, the first element of the array is a function used to make mutations. The arguments passed to the mutation is the variable of the graphql mutation&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;loading&lt;/code&gt; - the second element of the array returned from the “useMutation” hook is an object. loading becomes “true” after the mutation has been executed successfully&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;createTodo&lt;/code&gt; - is a const that contains the graphql mutation. You can test and structure a mutation using the graphql playground&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Getting all Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--atnHqU-z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/7365aa28-40e1-4099-bb7d-19547a894215" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--atnHqU-z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/7365aa28-40e1-4099-bb7d-19547a894215" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation :&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;useQuery&lt;/code&gt; hook is similar to the &lt;code&gt;useMutation&lt;/code&gt; hook. &lt;code&gt;useQuery&lt;/code&gt; gook is used to make graphql query request. It returns an Object. “data” property contains the response data of the query, while the “loading” property is the status of the request’s completion&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deleting Tasks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tog9EUBa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/115e7f1c-c4d3-41e9-a63c-fab220b70dc9" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tog9EUBa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/115e7f1c-c4d3-41e9-a63c-fab220b70dc9" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;onComplete&lt;/code&gt; callback function is called when a mutation is resolved. &lt;code&gt;deleteTask&lt;/code&gt; is a function used to perform a delete mutation. The arguments passed are the variables in the graphql mutation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Marking task as Complete (Update)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JrV9gFMJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/7bc77f69-87a8-4afc-af00-7583350b117d" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JrV9gFMJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://usecloudpressstorage.blob.core.windows.net/hosted-document-images/7bc77f69-87a8-4afc-af00-7583350b117d" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;updateTask&lt;/code&gt; function is similar to the previous mutations, but the first property of the variable object is the “id” property. The data property will contain all Fields in the database that you wish to update.&lt;/p&gt;

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

&lt;p&gt;If you made it this far congratulation In this article we migrated an AWS Appsync application to a Fauna application by creating a new database, connecting the fauna database to our react application and then we compared the structure of queries and mutations in Appsync and Fauna. Fauna is a really cool innovation and it is something I will advise every developer to start using. You should also check out their &lt;a href="https://docs.fauna.com/fauna/current/"&gt;official documentation&lt;/a&gt; for more information.&lt;/p&gt;

</description>
      <category>fauna</category>
      <category>serverless</category>
      <category>react</category>
      <category>graphql</category>
    </item>
    <item>
      <title>My Hacktoberfest Experience</title>
      <dc:creator>Akuagwu Philemon</dc:creator>
      <pubDate>Sun, 01 Nov 2020 17:39:58 +0000</pubDate>
      <link>https://forem.com/philzace1/my-hacktoberfest-experience-3ilf</link>
      <guid>https://forem.com/philzace1/my-hacktoberfest-experience-3ilf</guid>
      <description>&lt;h3&gt;
  
  
  [Intro Heading]
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;I am new to the DEV community, although I read DEV blogs, this is my first article here, I am Akuagwu Philemon, I am a full-stack developer. I am a passionate developer, with over 3 years of experience. I participated in Hacktoberfest 2019 and Hacktoberfest 2020 because I find it interesting and fun, dedicating a whole month to celebrate open-source and contributing to codes of company and individuals of a different nationality is really fun.&lt;/p&gt;

&lt;h3&gt;
  
  
  Progress
&lt;/h3&gt;

&lt;p&gt;I have completed my hacktoberfest challenge and the process has been really interesting, I made 5 Prs to 3 repositories&lt;/p&gt;

&lt;h3&gt;
  
  
  Contributions
&lt;/h3&gt;

&lt;p&gt;I contributed to 3 repositories but I am most proud of 1 which is &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Presto412/CryptoFS"&gt;https://github.com/Presto412/CryptoFS&lt;/a&gt;, I enjoyed contributing to this repo because it was the most interesting, I was tasked to implement AWS S3 bucket as a cloud storage solution, In a way that we hash the file and simply link similar files, to avoid uploading similar files twice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reflections
&lt;/h3&gt;

&lt;p&gt;I really enjoyed the whole Hacktoberfest experience, and I will surely do it again next year, I will also try to contribute to more open-source repos at my leisure&lt;/p&gt;

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