<?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 Kevin Nzioka on Medium]]></title>
        <description><![CDATA[Stories by Kevin Nzioka on Medium]]></description>
        <link>https://medium.com/@caveinncicad?source=rss-d6775ae91a4f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*w_GXwXNyGVaA_pR2.</url>
            <title>Stories by Kevin Nzioka on Medium</title>
            <link>https://medium.com/@caveinncicad?source=rss-d6775ae91a4f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 00:39:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@caveinncicad/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[Implement GraphQL Subscriptions with Flask]]></title>
            <link>https://medium.com/better-programming/implement-graphql-subscriptions-with-flask-7fa16e8b188d?source=rss-d6775ae91a4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fa16e8b188d</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Kevin Nzioka]]></dc:creator>
            <pubDate>Sat, 07 Sep 2019 19:37:44 GMT</pubDate>
            <atom:updated>2020-01-06T17:06:54.951Z</atom:updated>
            <content:encoded><![CDATA[<h4>Listen for database changes with GraphQL and Flask</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*XBYNfUuwJvpxr0QMFQspqQ.png" /><figcaption>Source: <a href="https://commons.wikimedia.org/wiki/File:Horn_flask_(PSF).png">Wikipedia commons</a></figcaption></figure><p>I recently needed to implement subscriptions on a Graphql application built on Flask. After searching the usual spots for a simple implementation I found nothing. Worry not — I came up with a hacky way to get around the problem. I hope someone else also finds it helpful.</p><p>To get started we set up a virtual environment using your favourite tool. I use pipenv.</p><p>You will need to install <a href="https://altair.sirmuel.design/">Altair GraphQL Client</a> which will enable us to test whether we have succeeded in implementing subscriptions.</p><p>We will require the following packages:</p><ul><li><strong>Flask</strong>: A web framework</li><li><strong>Graphene</strong>: A python library for building Graphql APIs</li><li><strong>Flask-graphql</strong>: Add graphql support to your Flask application</li><li><strong>Gevent</strong>: provides high-level synchronous API</li><li><strong>Flask-Sockets</strong>: Elegant WebSockets for your Flask apps</li><li><strong>Graphql-ws</strong>: websocket server for graphql subscriptions</li></ul><p>Before we do anything else, let’s create the folder from which we’ll be working.</p><pre>$ mkdir my_app<br>$ cd my_app</pre><p>Form now on we will be working from this folder. Install the packages:</p><pre>$ pipenv install flask graphene flask-graphql gevent flask-sockets graphql-ws</pre><p>Activate the pipenv shell:</p><pre>$ pipenv shell</pre><p>Create a folder and create app.py, which will be the main part of our application, and schema.py, which will contain our GraphQL schemas.</p><pre>$ touch app.py<br>$ touch schema.py</pre><p>In the app.py file initialize a flask application with GraphQL support:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28abeb050be585e1cc5c9f30e627d333/href">https://medium.com/media/28abeb050be585e1cc5c9f30e627d333/href</a></iframe><p>Have the schema to ensure you have something to import:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/386e8ebb96523a88290e75d4c84bef33/href">https://medium.com/media/386e8ebb96523a88290e75d4c84bef33/href</a></iframe><p>You can now run the flask server to ensure everything is working as intended by running this command:</p><pre>python app.py</pre><p>Visit the link localhost:5000/graphql and query the sample. Once you confirm it’s working it’s time to get to what brought you here: adding subscriptions to the API.</p><p>A bit of background: Subscriptions require web-sockets. For this, we use the graphql_ws package we installed earlier. From the documentation, it seems straightforward to apply it on a gevent server (which allows synchronous API calls). However, with Flask I found I had to do some overriding to get it to work.</p><p>First, we edit the app.py file to introduce sockets and change the GraphQL backend to one that supports subscriptions. We also need to create a new file, overriddenview.py, where we tweak the GraphQLView to allow it to support subscribable schema.</p><p>Your code should look something like the following. Don’t be scared by how long it is, it is actually quite simple in practice:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/231a95fa5496f32aea25b20716341151/href">https://medium.com/media/231a95fa5496f32aea25b20716341151/href</a></iframe><p>On the overridden.py file, the code is the exact code for a GraphQLView. However, the built-in GraphQLVIew doesn’t handle observables very well. Since the function that formats the execution results is not part of the class methods, we had to write a new class and have it use the functions that we custom made for it. In this case, the function that’s changed is format_execution_result.</p><p>We add the if statement to handle an instance where the returned data is an AnonymousObservable. The reason we have the function encode_execution_results on this file is that this is the function that calls the format_execution_result function, which we changed. On the built-in class, both these functions are defined on the file graphql_server — since we cannot change those particular files, we have to use this workaround. In the OverriddenView class that we use to override GraphQLView, it makes sure it calls the function we defined in this file, instead of those defined in the package.</p><p>Now, on the app.py we override the backend used by graphl since the default backend has allow_subscriptions set to false. We also set up sockets, which as we all know are an essential part of working with subscriptions to ensure a perpetual connection between your client and your backend. The gevent server is set up to allow us to have synchronous API calls.</p><p>We are almost done. All that remains is to define a subscription in the schema. We update the schema.py file as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a7359aa20a2df950ae68b58a9a0311b/href">https://medium.com/media/0a7359aa20a2df950ae68b58a9a0311b/href</a></iframe><p>We’ve defined a subscription which will count the number of seconds we pass in and alert us on every second. Now we run the app:</p><pre>$ python app.py</pre><p>We then launch the Altair Graphql client. We make a post request to localhost:5000/graphql, specify the subscription URL to ws://localhost:5000/subscriptions, and make a request with the graphql object:</p><pre>subscription{<br>  countSeconds(upTo: 10)<br>}</pre><p>It should then alert you every second for ten seconds.</p><p><a href="https://github.com/caveinn/flask_graphql_subscription">The Github repository for the code above</a></p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fa16e8b188d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/implement-graphql-subscriptions-with-flask-7fa16e8b188d">Implement GraphQL Subscriptions with Flask</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adapting to Challenges]]></title>
            <link>https://medium.com/@caveinncicad/adapting-to-challenges-e00bcca90d7d?source=rss-d6775ae91a4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e00bcca90d7d</guid>
            <category><![CDATA[andela]]></category>
            <dc:creator><![CDATA[Kevin Nzioka]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 11:35:19 GMT</pubDate>
            <atom:updated>2018-07-31T22:42:55.382Z</atom:updated>
            <content:encoded><![CDATA[<p>I love a good challenge as much as the next guy if not more. The last two weeks I have been lucky enough to be engaged with the Andela boot-camp. The experience has been with its fair share of challenges. In reading this I hope you will understand the challenges I have faced and the different ways I have handled them. Hopefully this will give you insight in some of the challenges you are facing.</p><p>The Andela boot-camp is a tough two week course that puts you through various technical and none technical tasks. When I got started I had a few other engagements that also required my attention. The difficulties started on the first week. I had to sit for two cats on one side while also completing a technical challenge on the Andela side. All this were to be done in the same week. At first I was perplexed. However, I took my time to decide the best course of action. After thorough deliberations with myself, I realized that since I was fairly good at the technical skills I would allocate more time to the preparations for the cats. The fact that am writing this blog on week two of the boot-camp persuades me that I made the right choice.</p><p>Secondly, there were the on site meetings. I live quite a way from the location the boot-camp is being held. I had to board two Matatus(local means of transport) to get to the boot-camp location. One of the routes I had to use is notorious for having heavy traffic. This was one of the hardest challenges to overcome. In the end I decided to be waking up early enough to beat the morning traffic. This solution had a problem that did not become apparent until week 2. I was spending most of my resting time traveling. The problem just doubled. Turned out the solution was who not where. Finally I decided to move in with a friend who lived at a nearer locale for the duration of the second week.</p><p>Reading this far you may be thinking this guys is really good at solving problems he faces. Well thats not always the case. On one instance I had overlooked one of the challenge requirement. A friend pointed it out to me on the final day before submission of the deliverable. The oversight was quite pronounced I had to restart the challenge because I had used a tool that was not required. When it was pointed out to me I felt my soul try to leave my body. I was quite saddened. I could not believe all the work I had done would go don the drain. I danced it off in my house to some loud house music(no pun intended ). After the empty feeling had left I informed my LFA(learning facilitator assistant) that I will not be able to submit the challenge before the deadline. He graciously gave me some lee way to submit later. Then I got down to business. The rest as they say, is history.</p><p>I cannot take all the crediting for adapting to the different challenges. My teammates have been critical in helping me adapt. As recently as yesterday we had a group challenge where we had to write a small program within an hour. I found it quite problematic since am used to starting programs by trying out different things and then settle on the one I feel most comfortable with. For this there was no time to do that. So my teammate proposed a model where you choose what you are going to use before you get started. I found this more fitting for the short timed challenge.</p><p>That is all I have time for now. Feel free to leave a comment. Looking forward to engage you in the next post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e00bcca90d7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interesting Attributes of My Teammates]]></title>
            <link>https://medium.com/@caveinncicad/interesting-attributes-about-of-teammates-3415e750bcc1?source=rss-d6775ae91a4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3415e750bcc1</guid>
            <category><![CDATA[andela]]></category>
            <dc:creator><![CDATA[Kevin Nzioka]]></dc:creator>
            <pubDate>Wed, 25 Jul 2018 10:39:21 GMT</pubDate>
            <atom:updated>2018-07-25T11:08:24.720Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing is not my strongest attribute, but today am going to enjoy it because I will be writing about some awesome people I got acquainted with recently. The said people are my teammates and my LFA (Lemah) who is the team member with the most experience. The team is called Prodigies (we believe we are). I already knew our LFA from a previous encounter in school (from reputation not personally). He is a great programmer. His joining Andela was one of the factors that encouraged me to apply. If a great skill like his could be improved by Andela then mine would be transformed. I first interacted with him personally on the boot-camp. Turns out he is a cool guy, and am not just saying that because he is going to read this but from the introduction, he felt like part of the team. All feedback gotten from him is very clear and one can easily act upon. It does not hurt that his hair is always on point.</p><p>Versatility is a great attribute to have in life. When I think about it one name comes to mind, Peter. Until recently he was a trained accountant who had never written code in his life. Now he is here helping in solving server connection issues. I cannot imagine myself making such a drastic career change. In that regard he is somewhat a hero. On top of learning to code in two months he also does photography as pastime and is a descent footballer. At this point, if he said he could fly, I would not doubt it. His coolness got quadrupled by the fact that he is my namesake. Kevin is his other name (Yes he has two English names).</p><p>We have the group clown Sammy. His witty jokes help to reduce the anxiety of approaching deadlines. He has the ability to find humor in most unlikely of places. In addition, it is quite unbelievable that he is a part-time musician. He is very friendly and social. We got along well as soon as we met even before we knew we would end up in the same group. I guess some things are fated. Traveling is on the list of his hobbies. This is one of the many interests we do not share. And for this reason I believe it makes us great teammates.</p><p>Then there is Rodgers, the playful one. He is a student at Technical University of Kenya taking computer technology. He is playful in a good way. He has the ability to remain unfazed by almost anything. He would be very cheerful while stuck on a bug he has no idea how to fix. In the end everything works out for him. He will tackle the challenge cheerfully, something I really envy about him. Windows is his favorite operating system a testimony to his love for gaming. Pick any computer game from sports to strategy and he will find a way to beat you in it.</p><p>Before I pen out guilt would consume me if I do not mention the fifth member of our group, Wilfred. He is a reserved guy who rarely talks but oozes wisdom every time he does.</p><p>That’s all for now. Hope you enjoyed the read.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3415e750bcc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Most Recent Challenging Learning Experience]]></title>
            <link>https://medium.com/@caveinncicad/my-most-recent-challenging-learning-experience-17b7dbbda6bd?source=rss-d6775ae91a4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/17b7dbbda6bd</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Kevin Nzioka]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 12:00:14 GMT</pubDate>
            <atom:updated>2018-07-24T19:24:21.900Z</atom:updated>
            <content:encoded><![CDATA[<p>Challenges are part of our daily lives, more so for those of us who relish them. This is a story of one such challenge. It is a story of pains and gains. Hopefully as you read this you will be inspired to overcome your own challenge.</p><p><strong>A new programming language</strong></p><p>I have had a great deal of interest in programming which informed even my decision for the course to study in university (Information Technology). It’s been 2 years since I discovered C programming language. I have hopped from one language to another, learning a lot on my hops (not to be confused with hopes). Recently I landed on php. I always shied from it since I was not all that interested in web development. Unrelenting invites from a friend wore me down. They claimed it was hard but I am not one to turn down a challenge. A new language is usually challenging especially when you are changing from a compiled language (Java) to a translated scripting language. My first challenge was learning to initialize a server and run my php scripts from there. It took a few tries and a lot of consultations since I was getting conflict on the ports. On overcoming that I was over the moon. Little did I know there was more ahead.</p><p>Learning the actual code was a piece of cake since I could transfer my knowledge from previous programming languages. However, the variable declaration took some getting used to. Perhaps it was the use of foreign currency ($) for each declaration (am quite patriotic). As I was getting used to the variable declaration, my next challenge came knocking.</p><p><strong>What on earth is a http request?</strong></p><p>I hadn’t heard of http request the magic behind web pages. Learning the different http methods and its various methods included excessive experimenting and reading. When I was getting started on the requests, I tried doing it on my own then got stuck on the different type of requests. It was time to swallow my pride and ask the friend who had introduced me to php. As it turns out there is no greater resource than people. He took me through the types one by one and since then, I have never had an issue with http requests.</p><p><strong>The mammoth that is databases</strong></p><p>The final challenge was integrating with a database. The only database I had worked on was derby db with Java. MySQL database was a new monster to me. I went at it for an entire week reading on and off, always having it at the back of my head. In the end I decided to head to a library and bury my head in php and mysql programming books. I will have to say that is the only burial I enjoyed. The information proved to be quite useful in getting the hang of things. By the end of the week I was one tired and radiant database expert (aspiring). I finished the project I had started to gauge myself (a church registration website).</p><p><strong>Vital lessons learned</strong></p><p>The knowledge I gained over that time has been applicable in many more undertakings since then. It was helpful as I had a better understanding of databases in other programming languages and the programming logic. I learned that pushing through challenges is as necessary to life as the challenges themselves are. In the process of handling this challenge, I learned the value of endurance and that failure is just an apostrophe to the story of your success. As the saying goes the only person who has never failed is one that has never tried anything new.</p><p>Thank you for reading. All the best in your future challenges.</p><p>Don’t forget to leave a comment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17b7dbbda6bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>