<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chukwualuka Chiama on Medium]]></title>
        <description><![CDATA[Stories by Chukwualuka Chiama on Medium]]></description>
        <link>https://medium.com/@chialukachiama?source=rss-3f9ab6b71bb2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Ihp2BIYDdmErGAmaCyfSHg.jpeg</url>
            <title>Stories by Chukwualuka Chiama on Medium</title>
            <link>https://medium.com/@chialukachiama?source=rss-3f9ab6b71bb2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:22:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chialukachiama/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Birth of the Hack Week]]></title>
            <link>https://medium.com/@chialukachiama/birth-of-the-hack-week-dc97fb693662?source=rss-3f9ab6b71bb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc97fb693662</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mentorship]]></category>
            <category><![CDATA[nigeria]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[teaching]]></category>
            <dc:creator><![CDATA[Chukwualuka Chiama]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 17:07:34 GMT</pubDate>
            <atom:updated>2019-10-28T17:07:34.057Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*oQ-QshDo_UXhXFjbmBTqBw.jpeg" /><figcaption>Image courtesy of <a href="https://medium.com/u/3f9ab6b71bb2">Chukwualuka Chiama</a></figcaption></figure><p>I took an introductory Computer Science in my first year in the university as a student of Accounting. It was nothing fancy. We didn’t do any coding. We just drew flowcharts and wrote some pseudo-code in BASIC. I thoroughly enjoyed it and wanted to explore some more. However, I didn’t have a laptop at the time. I decided to pursue other subjects I was interested in- Physics and Mathematics. I decided that I would come back to Programming while training for a Ph.D. in Physics.</p><p>Life does not always give what we want. I was denied a visa to go to the US to get the degree in Physics that I believed would set the rest of my future on course. It was a bitter disappointment. I had spent close to three years pursuing that dream and it was dealt a fatal blow in a visa interview that lasted less than ten minutes.</p><p>This was when I started considering going back to learn the programming I had a glimpse of many years back in the university. I knew absolutely nothing about software development. I did not even know how to start or where to start from. Help was soon to come though. Mentorship is probably the biggest gift any human can give another. My big brother, <a href="https://medium.com/u/4e9cdc42025f">Rowland Ekemezie</a>, gave me that gift. He set the ball rolling for me and set me up to succeed. Without his guidance and his help, chances are I might never have become a Software Engineer. That dream might have ended like many others- with the night.</p><p>It’s been more than one year and I have taken off already. However, I am not self-made. I have only made progress because some people committed to providing me with the guidance I had to have. It is time to give some of that help back. Many Nigerians lack the opportunity I had- mentorship and guidance. That has made all the difference for them.</p><p>This was how the initiative to teach others how to code was born. My bigger passion has, however, always been free education. I think it should be a fundamental human right. Education is too important to be denied anybody. <a href="https://medium.com/u/f33c58c52871">Ugo Ekemezie</a> gave me a much-needed push when he asked that I mentor some students who wanted to learn how to code. Acting on his prodding, we worked on arranging free code classes. We did some publicity and got people from different states in the country. I took them over the very basics of web development over a couple of classes held online. It’s time to take it a notch higher.</p><p>Acting on excellent advice from <a href="https://medium.com/u/4e9cdc42025f">Rowland Ekemezie</a>, we drew up plans for the first edition of a Hack Week. This edition will be held in Awka, Anambra state, from 4th to 8th November 2019. It will last for a week and I will be teaching participants the basics of web development free of charge. This will be the first of many series. It is a harbinger of many good things to come.</p><p>I know how important guidance is. I understand that what many people need to succeed is just someone who will point them in the right direction. This is the aim behind the Hack Weeks we will be doing. It will always be free for participants. We will provide electricity and internet connectivity for the participants so they can learn without hitches. I hope to reach as many communities in Nigeria as possible. More importantly, our focus will always be on how best to provide avenues for Africans to take advantage of the opportunities available in the tech sector. I know we will do more as time goes on. A journey of a thousand miles starts with a step and this is one more step to the thousandth mile. If talent is not nurtured it will go to waste. We already have too many unnurtured talents. One less is a victory for us all.</p><p>One hack-week will not make software developers of all that are interested in the profession. It will not even guarantee that all that partake continue to have careers in software development. It is a step though. The Igbo say that men should not stop fighting for fear of death. In other words, we should not allow fear of failure stop us from reaching for our dreams. How much this dream will yield cannot be told now. Cheers, though, to an excellent future!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc97fb693662" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a real time chat application with Node.js, GraphQL and React — 2]]></title>
            <link>https://medium.com/the-andela-way/how-to-build-a-real-time-chat-application-with-node-js-graphql-and-react-2-80ae53849e9b?source=rss-3f9ab6b71bb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ae53849e9b</guid>
            <category><![CDATA[the-andela-way]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Chukwualuka Chiama]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 18:01:11 GMT</pubDate>
            <atom:updated>2019-07-24T19:07:06.426Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to build a real-time chat application with Node.js, GraphQL and React — 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l7Zp6dx2DwFfFxJAnSdOfQ.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/3dman_eu-1553824/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1028794">Peggy und Marco Lachmann-Anke</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1028794">Pixabay</a></figcaption></figure><h4>What are we building?</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0NVE9uxRaJk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0NVE9uxRaJk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0NVE9uxRaJk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a8f91b8eb90deb246dc16a9b0aba127/href">https://medium.com/media/3a8f91b8eb90deb246dc16a9b0aba127/href</a></iframe><h4>Introduction</h4><p>In <a href="https://medium.com/the-andela-way/how-to-build-a-real-time-chat-application-with-node-js-graphql-and-react-1-d06cfbc52c8c">part 1 of this tutorial</a>, we succeeded in building a GraphQL server for a real-time chat application. Now, we’re going to build the frontend with React- and we’ll be using <a href="https://reactjs.org/docs/hooks-intro.html">React Hooks</a>. We’ll bootstrap this using <a href="https://github.com/facebook/create-react-app">create-react-app </a>and we’ll use <a href="https://www.apollographql.com/docs/react/">Apollo Client</a> to connect our GraphQL server to React.</p><p>We want our users to be able to register with an <em>email</em> and <em>username</em>. If they enter valid details, we’ll send the data over to our server to create a new user. Then we will save the user’s details in the browser’s local storage so that we can persist the session. Any logged-in user will see other logged-in users and can select any of them to chat with.</p><p>Please note that this is not an introduction to <a href="https://reactjs.org/docs/getting-started.html">React</a>, <a href="https://www.apollographql.com/docs/react/essentials/get-started">Apollo </a>or <a href="https://reactjs.org/docs/hooks-effect.html">React Hooks</a>. There are many other resources that do those well. I will assume you’re already a bit familiar with the React ecosystem. If you aren’t but have some programming experience, then you will be able to follow.</p><p>React Hooks were introduced in React 16.8. Ensure you have this version of React before attempting to use Hooks except you’re going to use the experimental version that was introduced before React 16.8. If you have used React before, you will love Hooks. They make code cleaner and easier to understand.</p><p>We won’t be able to show all our code here because of its sheer size. I’ll try to explain as we move along. Look out for ‘commented’ lines in GitHub gists that say what functions would be in those places. Don’t worry about those because you can get all of the code on <a href="https://github.com/LukasChiama/mini_chat_app">GitHub</a>. Skip over there to see the gist in full.</p><p>Now that you have a picture of what we want to achieve, let’s get to work. You can clone the repo from GitHub and take it out for a spin:</p><p><a href="https://github.com/LukasChiama/chat_app_client">LukasChiama/chat_app_client</a></p><h4>Install Dependencies</h4><p>Navigate to your root folder and on your terminal, run this if you have create-react-app installed globally:</p><pre>create-react-app client</pre><p>Clear the src/ folder of all unwanted files. Leave only the index.js, App.js and index.css files. Run this command on the terminal while in the src/ folder:</p><pre>$ rm app.test.js logo.svg app.css &amp;&amp; touch User.js Message.js Frontpage.js Message-Query.js User-Query.js</pre><p>Let’s install some dependencies:</p><pre>npm i graphql react-apollo apollo-link-ws subscriptions-transport-ws apollo-cache-inmemory</pre><p>If we weren’t implementing subscriptions, Apollo-boost might have been enough. For subscriptions, however, we need to implement some low-level functionalities that Apollo-boost doesn’t offer out of the box so we’ll use Apollo Client instead. We’re going to start by creating a WebSocket link for the subscriptions we’ll use to deliver our chat messages, an HTTP link for other communication with the server and initializing Apollo Client. You’ll be doing this in your index.js file like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a9ef15fcfddcf8405f37b8b1d68ccf4/href">https://medium.com/media/9a9ef15fcfddcf8405f37b8b1d68ccf4/href</a></iframe><p>We have both an HTTP link and a WebSocket link. Queries and mutations go over HTTP while subscriptions are done over the <em>ws</em> protocol. splitroutes each request to the appropriate link that will handle it. If it is a subscription, split sends the request through the wsLink route which if an instance of the WebSocket link. Otherwise, the request is sent through HTTP. To connect Apollo Client to our React app, we use the Apollo Provider component. This will wrap our React component, place the client on the context and provide it everywhere on the app. It’s always best to wrap your React app with the Apollo Provider high above anywhere you will need GraphQL data. That is why we are doing this in the index.js file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1262d0b2457847a8fd3607813a7e3ea6/href">https://medium.com/media/1262d0b2457847a8fd3607813a7e3ea6/href</a></iframe><p>User-Query.js, shown above, is where we define our GraphQL query string for all user queries, mutations, and subscriptions. Everything not shown follows the pattern of the UserQuery. We’re defining what we send to the server and what we get in return. These parameters were defined in the schema in the server. We’re wrapping our subscriptions, queries, and mutations, with the <em>gql</em> tag and defining the parameters each takes. The <em>gql </em>function takes the query strings we’ve written and parses them to the <a href="https://www.contentful.com/blog/2018/07/04/graphql-abstract-syntax-tree-new-schema/">GraphQL AST(Abstract Syntax Tree)</a>. If the query strings we wrote are successfully parsed to the GraphQL AST, then they can be validated and a response sent.</p><p>Let’s move on to our App.js file where we will implement User queries, mutations and subscriptions here. We‘re going to use <em>compose </em>and the <em>graphql </em><a href="https://reactjs.org/docs/higher-order-components.html">higher-order components</a> imported from react-apollo to connect Apollo to our React application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5bea4a0e1c8222207b779a3ddea508b/href">https://medium.com/media/c5bea4a0e1c8222207b779a3ddea508b/href</a></iframe><p>A lot of things are happening here. First, because we aren’t doing authentication we’ll just save the user logged in to local storage and pull it from there whenever the user returns. Then we’re using the useState hook for getting and setting state for both <em>receiverName</em> and <em>receiverMail</em>.</p><p>Subscriptions are set up in the <a href="https://reactjs.org/docs/hooks-effect.html">useEffect</a> hook. This hook provides you the functions of <a href="https://reactjs.org/docs/react-component.html">componentDidMount</a>, <a href="https://reactjs.org/docs/react-component.html">componentDidUpdate</a> and <a href="https://reactjs.org/docs/react-component.html">componentWillUnmount</a> all combined. It’s the ideal place to set up subscriptions. To define the subscriptions we want to listen to, we are going to use the <a href="https://www.apollographql.com/docs/react/advanced/subscriptions/#subscribetomore">subscibeToMore</a>function. With the subscribeToMore, you can define the subscription you want to listen in on and then pass arguments if you’ve specified any parameters on the server. For the <em>addUserSubscription</em>, we want to get new users and broadcast them immediately to everybody. When a user is deleted, we also want to broadcast that user to everybody.</p><p>Next, we define the functions passed to our <em>graphql </em><a href="https://reactjs.org/docs/higher-order-components.html">higher-order component</a> and pass the arguments needed for the server to execute them. We’re going to be doing <a href="https://www.apollographql.com/docs/react/features/optimistic-ui">optimistic UI updates</a> courtesy of the <a href="https://www.apollographql.com/docs/angular/features/cache-updates/">Apollo store</a>. When a new user is created with the createUser function, we update the Apollo store so that our data is not only sent to the server but we see the mutation take effect on the client immediately. Notice that with the <em>graphql</em> higher-order functions wrapper with compose, we’re injecting data to the App component as props from Apollo Client. For example, the createUserMutation is provided to us as props, we gave it an alias as createUser and then we called the function and provided arguments defined on the server for the function to run.</p><p>In the return statement, we’re sending users to the <strong>User</strong> component. We will render users there. We’ve also defined a callback function, setSelectedMail, that we’re passing as props to the child component. Let’s hop over to the <strong>Message</strong> component to see how to set up <em>message</em> and <em>userTyping</em> subscriptions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/656ad60b7a3a8874445c0a1ca4fd5bec/href">https://medium.com/media/656ad60b7a3a8874445c0a1ca4fd5bec/href</a></iframe><p>To implement the <em>userTyping</em> subscription, we have the advantage of React’s onChange handler function for controlled elements in forms. When we define the function, we want to do more than just change the state of the input element. We pass in the email of the user typing as well as the email of the user at the receiving end. We also want a setTimeout that will fire after 2000ms, sending dummy arguments to the function, so that if the user stops typing, the typing notification will end. To ensure that multiple setTimeout functions don’t get stacked, we clear them with clearTimeout.</p><p>In the server, we used the withFilter() function to specify that users should only get subscriptions when the <em>receiverMail</em> on the variable we provide is same as the <em>receiverMail</em> on the payload from the <em>userTyping</em> mutation. We just passed the payload in the handleChange() function. We’re going to pass this variable in the <em>useEffect</em> Hook. You’ll notice that in this Hook, we’ve defined the variable, <em>receiverMail</em>, and assigned an email to it. The logic is this: when I’m typing I notify the server of the user I’m sending a message to by specifying the user’s email- receiverMail. I want the server to return my email, but only if this user has my email as their receiverMail, and that will only be a user chatting with me. And with that, you get notified only when the user you’re chatting with is typing.</p><p>In the return statement, we’re simply doing a check and displaying messages that have the user’s email either as <em>senderMail</em> or as <em>receiverMail</em>. Every user gets messages she has sent or received.</p><p>Aside from the component that renders our users, which I mentioned above, the only thing left in our app is a front-page with a form for users to use for logging in. We’ve passed a callback from the App component so that when a user submits this form, the createUser function in the App component is implemented and a new user is created. Quickly check the <a href="https://github.com/LukasChiama/mini_chat_app">repo on GitHub</a> to see the details.</p><p>There you go. You have a fully functional real time chat application working. I hope you enjoyed this and found it interesting. I sure did. To prevent this from becoming too long and boring, I’ll have to stop here.</p><p>Run npm start, head over to localhost:3000 and have some fun.</p><p>There are lots of other implementations I would love to add that you can implement on your own to learn some more. Top on the list for me would be push notifications. A chat app should have push notifications, shouldn’t it? Yeah yeah… That will be a lesson for another day though. You could add proper authentication so that users sign up and then log in with their emails and passwords. You could also integrate social media login so users can log in with Facebook, Twitter, Google or even GitHub. There’s so much fun stuff to do…</p><p>Well, thank you very much, good reader, for taking out time to read this. Comments and suggestions would be appreciated. I’d love to hear other opinions and learn some more. Questions will also be welcome. Use the comment box as you wish.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ae53849e9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-andela-way/how-to-build-a-real-time-chat-application-with-node-js-graphql-and-react-2-80ae53849e9b">How to build a real time chat application with Node.js, GraphQL and React — 2</a> was originally published in <a href="https://medium.com/the-andela-way">The Andela Way</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a real time chat application with Node.js, GraphQL and React — 1]]></title>
            <link>https://medium.com/the-andela-way/how-to-build-a-real-time-chat-application-with-node-js-graphql-and-react-1-d06cfbc52c8c?source=rss-3f9ab6b71bb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d06cfbc52c8c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[the-andela-way]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Chukwualuka Chiama]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 12:23:50 GMT</pubDate>
            <atom:updated>2020-07-03T21:23:50.254Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to build a real-time chat application with Node.js, GraphQL and React — 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l7Zp6dx2DwFfFxJAnSdOfQ.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/3dman_eu-1553824/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1028794">Peggy und Marco Lachmann-Anke</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1028794">Pixabay</a></figcaption></figure><h4>Introduction</h4><p>Together, we are going to navigate some common ground. We will use some wonderful technologies to produce a useful tool while catching some of the fun that software development delivers.</p><p>We are going to build a real-time chat application using <a href="https://nodejs.org/en/">Node.js</a>, <a href="https://github.com/prisma/graphql-yoga">GraphQL</a>, <a href="https://www.mongodb.com/">MongoDB</a>, and yes, we’re using the all-new and shiny <a href="https://reactjs.org/docs/hooks-intro.html">React Hooks</a>. Our app will allow users to log in and see all logged-in users per time so that they can select and chat with any of them. Users will also get notifications when new people join the chat and when those they are chatting with are typing. Sounds good? Great, let’s get to work!</p><p>When I started learning backend web development, I got into GraphQL purely by chance. I searched for a full-stack tutorial on YouTube and the most recent I saw used GraphQL. I took the tutorial not knowing what GraphQL was or what the alternatives were. Needless to say that my learning was fraught with avoidable difficulties at many stages. I spent a lot of time reading through different pages of GraphQL documentation and scouring through the few answers available on StackOverflow for the many questions I had. I was struck by the relative lack of materials on GraphQL despite the many promises it offers and delivers on. Writing this is my way of paying this wonderful dev community back so you, the good reader, can learn faster than I did.</p><p>In order to avoid this tutorial being longer than necessary, I won’t spend a lot of time talking about our tech stack. There are already many wonderful resources that do that. This tutorial is also divided into two parts. This is the first and it will cover designing the server. <a href="https://medium.com/the-andela-way/how-to-build-a-real-time-chat-application-with-node-js-graphql-and-react-2-80ae53849e9b">In the second tutorial</a>, we will build out the frontend of the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*2Ey7YLPx3ZXFAPx9D4ntgw.jpeg" /><figcaption>Now, let’s make magic!</figcaption></figure><p>Let’s get into the action. The code for this app is on GitHub. You can clone the repo and check out the code:</p><p><a href="https://github.com/chialuka/chat_app_server">chialuka/chat_app_server</a></p><p>This is a very simple app and we will employ a simple file structure. In the end, our server folder will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6db2d3287bd02e6f9e374977b9e61809/href">https://medium.com/media/6db2d3287bd02e6f9e374977b9e61809/href</a></iframe><h4>Setup server</h4><p>We’re going to use <a href="https://github.com/prisma/graphql-yoga">GraphQL-yoga</a>. It is a fully-featured GraphQL server that is very easy to set up. GraphQL is a Query Language for APIs developed by the folks at Facebook as an alternative to REST. It is also a runtime for fulfilling those queries. GraphQL is an alternative to the REST architecture for designing APIs that is geared towards giving clients the power to ask the server for exactly what they need from the database. This they get and nothing more. Sweet, isn’t it?</p><p>We will use <a href="https://mlab.com/">mLab</a> and the Mongoose library. Refer to the <a href="https://docs.mongodb.com/v3.2/administration/install-community/">MongoDB official docs</a> if you want to get it installed locally so you’ll use a local instance. I’ll be using mLab for this because this app is hosted on Heroku. mLab is a database-as-a-service provider for MongoDB. It provides us with free MongoDB database instances on the web. You can look at <a href="https://medium.com/@alialhaddad/how-to-setup-a-online-mongo-db-database-using-mlab-24bb583720ba">this</a> if you need help setting mLab up.</p><p>Now, initialize npm and install the dependencies we need for the project.</p><pre>$ npm init -y<br>$ npm i graphql-yoga mongoose</pre><p>In the index.js file, import these dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71ca97b1443b0d7d861fddeb3dcdeefc/href">https://medium.com/media/71ca97b1443b0d7d861fddeb3dcdeefc/href</a></iframe><p><em>GraphQLServer</em> is the core primitive provided by <em>graphql-yoga </em>and will create an instance of our server for the magic to happen. This server comes configured with everything related to the <em>GraphQL schema</em> as well as the basic server configuration. <em>PubSub</em> and <em>withFilter</em> will be used for the GraphQL subscriptions that will make our app real-time. We’ll get to these in a bit.</p><p>Next, connect mongoose to your database. If you don’t pass in the first two arguments you’ll get <a href="https://mongoosejs.com/docs/deprecations.html">deprecation warnings</a> from Mongoose.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5991899a720c454ade2a62b31948cba8/href">https://medium.com/media/5991899a720c454ade2a62b31948cba8/href</a></iframe><h4>Models</h4><p>Next, create your Mongoose models and pass in your schema to it. This is a simple app so we’ll need only two models- <strong>User</strong> and <strong>Message</strong>. Let’s write this into the models.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f834ab6f93d807a0d0b279ae8f6ff87/href">https://medium.com/media/2f834ab6f93d807a0d0b279ae8f6ff87/href</a></iframe><p>We want <strong>emails</strong> to be unique since we’ll be using them to identify our users. We also want both <strong>name</strong> and <strong>email</strong> fields to be compulsory.</p><h4>TypeDefs</h4><p>We can either provide a schema to our GraphQL server or use <em>typeDefs</em> and <em>resolvers</em>. We’ll use the latter here. TypeDefs define the schema models we want and specify what each model should contain. They define the structure of the GraphQL API and are written in <a href="https://www.prisma.io/blog/graphql-sdl-schema-definition-language-6755bcb9ce51">GraphQL SDL</a> (Schema Definition Language). They also define the GraphQL <em>operation types</em> we want to use. There are three operation types available- <em>queries</em>, <em>mutations</em>, and <em>subscriptions</em>. <em>Queries</em> and <em>Mutations</em> have a special place as the entry points into the schema. <em>Queries</em> are used for requesting data. They perform the <strong>R-Read</strong> in the CRUD functions. <em>Mutations</em> are, well, mutations. They allow us to <em>mutate </em>data. Haha… <em>Mutations</em> allow us to modify data on our models. They are used for the <strong>C-Create</strong>, <strong>U-Update</strong> and <strong>D-Delete</strong> functions. <em>Subscriptions</em>, on the other hand, are used to create and maintain a real-time connection with the server. Refer to <a href="https://graphql.org/learn/queries/">this </a>and <a href="https://www.prisma.io/blog/graphql-sdl-schema-definition-language-6755bcb9ce51">this </a>for more information. Create a typeDefs.js file and write this code in. Don’t forget the backticks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8f1d4ea2ba44deb0604a9f9702412a7/href">https://medium.com/media/d8f1d4ea2ba44deb0604a9f9702412a7/href</a></iframe><p>We have defined <strong>User</strong> and <strong>Message</strong> types as well as <strong>query</strong>, <strong>mutation</strong>, and <strong>subscription</strong> operation types. All of these are object types and are the most basic components of a GraphQL schema. With them, we can define what we can fetch from the server. Note that this is language agnostic and is therefore not limited to a Node.js backend.</p><p>Notice that <strong>User</strong> contains a field for messages. This provides us an array of messages related to the particular User we query. <strong>Message</strong> also contains a reference to the user that created it. We’re using this to connect a user to the messages he/she sends.</p><p>Our mutations specify the fields we want and what we want to return from the mutation. For the <strong>createUser</strong> mutation, we want the user to provide a name which is a string. The exclamation mark (!) there signifies that this is a required field and cannot be null. The new user will not be created if this field isn’t provided. We also want a required email that is a string. If the operation is successful, we want the created User returned. That’s what the <em>User!</em> outside the parenthesis is doing. It specifies the value returned from the mutation. Other mutations follow the same logic. Notice that although we didn’t create an <em>id</em> we require it for some mutations. This is possible because the <em>id</em> is automatically generated for every instance of our model that is created.</p><p>A cool feature to implement would be the notification chat applications give when the other person is typing. And we’re going to implement it! Yeah! That’s what the <em>userTyping</em> mutation will do. We are simply creating a mutation that we can listen in to with a subscription. For the subscription to work we need to know the user typing and the user the message is for. That’s why we’re passing <em>email</em> and <em>receiverMail</em> to the <em>userTyping </em>mutation. Cool…</p><p>For the <em>newMessage</em> subscription, we want to get all new messages associated with the receiver mail we provide. We don’t want all users receiving any new message anybody sends. You only receive a message from the user you’re chatting with. We will instruct the server to send us any message the person with the email we provide sends. We’re also doing the same thing for the <em>userTyping</em> subscription. This will enable us to know not just when the person we’re chatting with has sent a message but also when he/she is typing. However, for <em>newMessage</em> we want the message created returned. When typing, we will only return an email for identification.</p><p>For the <em>newUser</em> subscription, we want all of the new users returned immediately any is created. This subscription will allow anyone using the app to see new users immediately they join. The <em>oldUser</em> subscription removes deleted users from our app. For these two, we want all users of the app notified so we aren’t requiring any parameters.</p><h4>Query Resolvers</h4><p>Now on to our resolvers, create a resolvers.js and write this in:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd59efb4d2421bf66a1f3a62f4023f17/href">https://medium.com/media/bd59efb4d2421bf66a1f3a62f4023f17/href</a></iframe><p>Resolvers are functions for the object types defined under <em>typeDefs</em>. Remember we said earlier that <em>typeDefs </em>define the structure of the GraphQL API we’re building? Well, <em>resolvers </em>are the implementation of the API. We’ll define <em>resolvers</em> for all the object types already specified under <em>typeDefs</em>. For the queries in the gist above, we’re simply searching for all items in the query category and returning them. Running a query on either User or Message will return all the database entries for them.</p><p>For either <strong>User</strong> or <strong>Message</strong> query, we need to find related content and return it when we run the query. We want to attach all messages created by a user to that same user and vice versa. For <strong>User</strong>, we want to use the user’s email to search through messages and return those that have that same email as <em>senderMail</em>. Likewise, on the Message query, we want to find the user responsible for sending each individual message. Remember this is still part of our resolvers just like the Query field already written in above. Write this code in:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb273f6f6e4d7f7690c54d4443c35437/href">https://medium.com/media/eb273f6f6e4d7f7690c54d4443c35437/href</a></iframe><h4>Mutation Resolvers</h4><p>On to resolvers for our mutations. We will take in the values we requested for in <em>typeDefs</em> and either create a new object, modify the existing one or delete it. For these database interactions, we will use asynchronous functions to avoid making blocking I/O calls. Our async function will return a promise that we will <em>await. </em>We could use callbacks for this but this is way neater, isn’t it? This app will not implement the update functions on the front end. They are here as guides for you in developing other apps that will need them. Resolvers take four arguments: <em>obj</em>, <em>args</em>, <em>context, </em>and <em>info. </em>We only need to use <em>args- </em>argument for this app.</p><p>Remember we want the server to notify us when a new user or message is created and then when a user is deleted or a user is typing. This is exactly what the <em>pubsub.publish</em>() function will do on our mutations below. It exposes a <em>publish</em> and <em>subscribe</em> API that will allow us to subscribe to additions to this field and get those fields published on the client. When the resolvers for these mutations are called, <em>pubsub</em> is called too and it publishes the details we specify to the client. When a user is deleted, we also want to find all messages the user has sent and then delete them as well. To do this, we’ll use a <em>Promise.all</em>() function to await the user and message deletions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb273f6f6e4d7f7690c54d4443c35437/href">https://medium.com/media/eb273f6f6e4d7f7690c54d4443c35437/href</a></iframe><h4>Subscriptions</h4><p>Subscriptions are powered by WebSocket and not HTTP. WebSocket is a computer communications protocol, like HTTP, that provides full-duplex communication channels. This allows the server to send messages to the client the same way the client can send messages to the server. In HTTP, the request is always initiated by the client while the server processes the response. HTTP is uni-directional while WebSocket is bi-directional. It is perfect for finding out when a new message or user has been created in the database and sending the info to the client.</p><p>Let’s write our resolvers for the subscriptions we’re interested in. With <em>pubsub.asyncIterator</em>(), we map the event we’re interested in by passing in the subscription name as an argument. This defines the subscription for the GraphQL engine. Now, every time <em>pubsub.publish</em>() is called on this subscription, like when a resolver we defined <em>pubsub.publish</em>() in is called, it is published for us. Yippie! We’ll be using the <em>withFilter</em> API on our <em>newMessage</em> and <em>userTyping</em> subscription. It provides us with a filter function so that we can define what subscription we want to be published. We’re only interested in publishing these to the client the message is meant for. On the client we’ll pass the argument that will determine what subscription will be pushed to a particular user. We don’t want filters on new users and deleted users though. We want everyone to see them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d521997b9c14e3b5fa7861408e4b8155/href">https://medium.com/media/d521997b9c14e3b5fa7861408e4b8155/href</a></iframe><h4>Conclusion</h4><p>Finally, for the back end, make sure to create an instance of <em>PubSub</em> and to create and start your server. Notice that we pass <em>pubsub</em> to our GraphQLServer as context. This is to enable the server access <em>pubsub</em> in our resolvers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c68d42b07759fec7177cfceb82bc6df9/href">https://medium.com/media/c68d42b07759fec7177cfceb82bc6df9/href</a></iframe><p>Run your server with this command</p><pre>node index.js</pre><p>I use <a href="https://www.npmjs.com/package/nodemon">nodemon</a> so I won’t have to restart the server on any change. Nodemon watches the index.js file and automatically restarts the server when you save any change. Install <em>nodemon</em> as a dev dependency (a dependency you will only in development and not in production) by running:</p><pre>npm i -D nodemon</pre><p>Now include it in the start script in your <em>package.json</em>:</p><pre>&quot;scripts&quot;: {</pre><pre>&quot;start&quot;: &quot;nodemon index.js&quot;</pre><pre>},</pre><p>Now you can run npm start to start the server and nodemon will restart the server whenever you make changes.</p><p>The code is here if you need to confirm anything:</p><p><a href="https://github.com/chialuka/chat_app_server">chialuka/chat_app_server</a></p><p>Navigate to <em>localhost:4000</em> on your browser. With GraphQL-yoga, you can use the <a href="https://www.prisma.io/blog/introducing-graphql-playground-f1e0a018f05d">GraphQL Playground</a>, an IDE for working with GraphQL APIs. It even supports subscriptions so you can test everything you’ve written. Congratulations, you have a running real-time chat application server!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VlOx7nyTF21occ5TOVimQ.png" /></figure><p>Well, thank you very much, good reader, for taking out time to read this. Comments and suggestions would be appreciated. I’d love to hear other opinions and learn some more. Questions will also be welcome. Use the comment box as you wish.</p><p>Now, let’s hop over to <a href="https://medium.com/the-andela-way/how-to-build-a-real-time-chat-application-with-node-js-graphql-and-react-2-80ae53849e9b">part 2</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d06cfbc52c8c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-andela-way/how-to-build-a-real-time-chat-application-with-node-js-graphql-and-react-1-d06cfbc52c8c">How to build a real time chat application with Node.js, GraphQL and React — 1</a> was originally published in <a href="https://medium.com/the-andela-way">The Andela Way</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code and Bonds]]></title>
            <link>https://medium.com/@chialukachiama/code-and-bonds-81a1353fea68?source=rss-3f9ab6b71bb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/81a1353fea68</guid>
            <category><![CDATA[friendship]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[andela]]></category>
            <category><![CDATA[relationships]]></category>
            <dc:creator><![CDATA[Chukwualuka Chiama]]></dc:creator>
            <pubDate>Mon, 10 Jun 2019 12:52:37 GMT</pubDate>
            <atom:updated>2019-06-10T12:52:37.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ol1r69oOaesora63sHcm5A.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@nappy?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">nappy </a>from <a href="https://www.pexels.com/photo/six-men-standing-while-laughing-936006/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>I met Martins Obayomi on the day we were interviewed. We didn’t exchange greetings. Each person was busy contemplating what the future held. We probably nodded at ourselves in acknowledgment. A few weeks later we met during pre Bootcamp workshops and he recognized me first. We said our his and he asked of a fellow participant at the Bootcamp who I had made friends with on the interview day. From then on, we’d say hi every once in a while. I still didn’t know he was called Martins and he didn’t know the name Chukwualuka.</p><p>During the final week of Bootcamp, he came to me with a problem he had. His build was failing on Heroku. For the first time since we met about a month before then, we really talked. I shared some tips with him that helped me when I faced the same dilemma and we agreed to talk on Slack so I would know if the same tips helped him too. The problem was solved and all was well in paradise. Bootcamp ended and Martins and I were on the wait. We exchaged messages on Slack while waiting to know our fate. Around 8:00 pm that evening, we got our offers from Andela. We were going to be Andela fellows! We exchanged messages within minutes congratulating each other and sharing how often we refreshed our emails out of anxiety.</p><p>Our bond would go up a few notches higher when three weeks later we both found out we belonged to the same team in the deferral programs. We were a bit familiar with ourselves but we weren’t close. The deferral program paved the way for a huger bonding. One of the things that struck me the most about Martins was his energetic optimism. Martins had problems I don’t have. His laptop had been faulty from bootcamp and it severely limited his productivity. He still found a way to make it through bootcamp and get accepted into the fellowship. He lives in an area of Lagos where electricity is hardly ever available. He substitutes this by using a generator as much as his budget can allow.</p><p>Despite these challenges, he agreed to take on the Deferral Programs. When I talked to him about prospects for the program, he told me that after the programs we would have learned useful skills that would carry us through simulations and apprenticeship. He was excited. He wasn’t worried about the lack of remuneration and the hours of work involved. He wanted to learn and he did all he could to. That level of optimism finds a way to rub off. I found myself sharing more of his optimism. I had found a companion who would take on difficult challenges without batting an eyelid and still have the heart to laugh at himself when making mistakes.</p><p>I would guess he learned some optimism from playing football. Martins is an avid football player. He plays football almost weekly. I also think it’s a character he has built over the years. Over the past week that his laptop crashed for the umpteenth time, he borrowed a friend’s laptop just to get work done. He would work with the laptop for some time, return it to the friend, and then borrow it later to keep working. I was absolutely impressed. He could simply have stopped work because his laptop was faulty. Everybody would understand. But he went the extra mile to borrow one. My admiration went up notches higher when he shared with me how he had to install Node.js, PostgreSQL PG Admin, VSCode Editor and other apps that have become second nature to us. We laughed and I teased him about using Titanic as an example on his PR. I teased him about falling in love and forgetting how to write proper JSDoc all because of Titanic. His response was to warn me to avoid him when we resume.</p><p>Of course we both laughed. He really meant we were going to share a special handshake we we resume. We will share a handshake that marks us, not just as colleagues or as team members but as friends. We should shake the way friends shake, with the heart and not just with the hands- a testimony to another bond code has made.</p><p>Thank you for reading this. I hope you Martins optimism and eagerness to learn has also rubbed off on you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81a1353fea68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lunatic Lover]]></title>
            <link>https://medium.com/@chialukachiama/lunatic-lover-3b4a6b3750d2?source=rss-3f9ab6b71bb2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b4a6b3750d2</guid>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[infatuation]]></category>
            <category><![CDATA[heartbreak]]></category>
            <category><![CDATA[prose-poem]]></category>
            <category><![CDATA[love]]></category>
            <dc:creator><![CDATA[Chukwualuka Chiama]]></dc:creator>
            <pubDate>Mon, 11 Mar 2019 07:35:21 GMT</pubDate>
            <atom:updated>2019-03-11T15:18:29.188Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTfHf3EwraV6pj-1okpoMA.jpeg" /><figcaption>&lt;a href=”<a href="https://pixabay.com/photos/sculpture-faux-statue-painting-2413080/">https://pixabay.com/photos/sculpture-faux-statue-painting-2413080/</a>&quot;&gt;Image&lt;/a&gt; by &lt;a href=”<a href="https://pixabay.com/users/BarbeeAnne-516629/">https://pixabay.com/users/BarbeeAnne-516629/</a>&quot;&gt;BarbeeAnne&lt;/a&gt; on Pixabay</figcaption></figure><p>It is not out of place that I found you today after searching for days that ran into weeks and weeks that ran into months. The voices, both within and without my head, always assured me I would find you. It was your smile I saw first, that smile that is the color of the flow of Osimiri the great river- quiet and graceful. But I expected you would run to me and assuage me with warm kisses. Instead, the cold smack of your eyes, like the thrust of the Samurai’s cherished sword, cut my excitement down to size and left it gasping for breath.</p><p>I would have found a bag your size and bundled you into it. Then I’d take you back to the house and place you back in the frame in mother’s living room. But I thought that would not win your affection. You’d call me a kidnapper, or worse a caveman, then stain the paint on the canvas with your tears.</p><p>Then I thought of cleaning your face of the ungainly stains of leanness etched in your creases. You used to be like the well-fed African woman, robust and rotund, and the colors lingered on your cheeks before bouncing off into my eyes. But I thought that wouldn’t win your affection either. You’d call me an unfeeling, ceremonial lunatic. Then you’d throw my brushes at my face and scrounge your immortal eyes in unforgiving sorrow.</p><p>And you’ll laugh and fear when you tell your friends of the sentimental fool whose canvas you stained with tears and whose brushes you threw back full in the face. Your friends will shriek in oohhs and aahhs and secretly wish it was them I loved. They will not remind you that our destinies are like the roped pots of Igbo Ukwu- long and clinging. They will not tell you that destinies are like the patterns on butterflies- they are locked in and sealed after they have been painted. Your friends will not tell you must have me or no one else.</p><p>These your friends, of course they do not hear the many whispers we exchange every night in my dreams. I tried to remind you but you were too busy shouting and cheering the lunatic cops and more lunatic judges you and those lunatic friends called to bundle me away- cheering them as they came for me. I saw these ropes by the roadside and knew they were better than any bag I could hope to take you back in. I only came at you with these ropes because they would have been comfortable transport for taking you back home.</p><p>I wanted to tell you I’d been searching for you since you dropped out and left the frame and canvas empty. I wanted to remind you of how your face lit up whenever I came into the room, like the sky when the candle light of the stars are turned on and tell you how your absence was the solar eclipse that abruptly stole the life from our world. I wanted to remind you of dreams and of songs, of snuggles and of giggles, and of the many tales you listened to as I told them by the wane light in mother’s living room. I wanted to tell you that your lips, Mona Lisa, were drawn for smiling, not for shouting with lunatics. And now these lunatic cops that you called will not let me near you. Worse still, they will not take this message to you.</p><p><em>Thank you for reading. Claps will be very much appreciated. Take a look at some of my work at </em><a href="http://lukaschiama@blogspot.com/"><em>muSings</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b4a6b3750d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>