<?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 Fabien de Maestri on Medium]]></title>
        <description><![CDATA[Stories by Fabien de Maestri on Medium]]></description>
        <link>https://medium.com/@FdMstri?source=rss-d9ca5be78595------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*f0Zsq1isMvk54RbF.png</url>
            <title>Stories by Fabien de Maestri on Medium</title>
            <link>https://medium.com/@FdMstri?source=rss-d9ca5be78595------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:48:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@FdMstri/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[DocAi: Leveraging AI for Your Documentation Needs]]></title>
            <link>https://medium.com/@FdMstri/docai-leveraging-ai-for-your-documentation-needs-86a754f1115b?source=rss-d9ca5be78595------2</link>
            <guid isPermaLink="false">https://medium.com/p/86a754f1115b</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Fabien de Maestri]]></dc:creator>
            <pubDate>Mon, 18 Sep 2023 09:30:49 GMT</pubDate>
            <atom:updated>2023-09-18T09:30:49.517Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of development, quality documentation is paramount. It ensures that code is understandable and seamlessly usable by other developers. But what about keeping it updated? What if I told you your documentation could be generated and updated automatically straight from your JS/TS code?</p><h4>What is DocAi?</h4><p>DocAi is an open source automated tool harnessing the power of artificial intelligence to convert your JavaScript or TypeScript code into comprehensive Markdown documentation. No more manual updating of your documentation; DocAi handles it for you.</p><p>Integration with Entry Points and Serverless Configurations<br>One of DocAi’s standout features is its adaptable integration capabilities. You can harness this powerful tool in two primary ways:</p><ol><li>Defined Entry Points: If your project has a clearly defined entry point, such as an index.js or app.ts, DocAi can initiate its scan from this file. It traces the dependencies and references, ensuring every piece of the puzzle gets captured in the generated documentation.</li><li>Serverless.yml Projects: For those leveraging serverless architectures with a serverless.yml configuration, DocAi offers tailored support. It intelligently identifies the defined routes in your serverless setup. From there, DocAi doesn&#39;t just document functions or methods—it generates comprehensive documentation for each route, providing clarity on their functionalities, parameters, and expected behaviors.</li></ol><h4>Use cases: Keeping Documentation Up-to-date</h4><p>Let’s envision a few common software development scenarios:</p><ul><li><strong>Continuous Integration (CI)</strong>: Each time you push a code update, your CI could automatically trigger DocAi to refresh the documentation. This ensures your documentation always mirrors the current state of the code.</li><li><strong>Code Reviews:</strong> When a colleague submits a pull request, you can use DocAi to generate temporary documentation. This can assist in swiftly grasping the changes made.</li><li><strong>Onboarding New Members:</strong> With perpetually updated documentation, new developers can understand the existing codebase quicker, easing and expediting their integration into the project.</li><li><strong>Integration with Docusaurus:</strong> Once DocAi has generated the Markdown documentation, you can pair it with Docusaurus to transform this documentation into a fully-fledged website. This not only enhances accessibility but also adds a professional touch to your documentation presentation.</li></ul><p>One significant advantage of using DocAi is its ability to maintain the original file and folder structure of your codebase in the generated documentation. This preservation of the initial hierarchy ensures that the documentation mirrors the organization of your project. Consequently, any developer diving into the code can grasp its structure and functionality with greater clarity.</p><h4>Why Should You Give DocAi a Try?</h4><p>The purpose of this article is to pique your interest in DocAi. Being open-source, the project’s success leans heavily on the community. Your feedback is invaluable to us. By trying out the tool and sharing your experiences, you assist us in refining DocAi. We aspire to make sure it can document any codebase, no matter the complexity.</p><h4>In Conclusion</h4><p>Documentation stands as a pivotal facet of software development. It safeguards code comprehensibility for all. With DocAi, you have the opportunity to automate this process, ensuring ever-present, updated documentation. So, why not give it a go?</p><p>Interested? Head over to <a href="https://github.com/zgababa/docai">https://github.com/zgababa/docai</a> to dive into DocAi!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86a754f1115b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7 professional skills that I learned from 1 year of traveling]]></title>
            <link>https://medium.com/@FdMstri/7-professional-skills-that-i-learned-without-working-for-1-year-65fb9aa42d80?source=rss-d9ca5be78595------2</link>
            <guid isPermaLink="false">https://medium.com/p/65fb9aa42d80</guid>
            <category><![CDATA[change]]></category>
            <category><![CDATA[work]]></category>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[skills]]></category>
            <dc:creator><![CDATA[Fabien de Maestri]]></dc:creator>
            <pubDate>Thu, 13 Sep 2018 07:50:29 GMT</pubDate>
            <atom:updated>2018-09-18T16:23:57.850Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XUgYq6AECK4UtoKfsyJXsg.jpeg" /><figcaption>Monk watching the horizon, Vietnam</figcaption></figure><p><em>Taking 1 year to discover Asia was one of the hardest decisions of my life. It turned out to also be the best. My biggest fear was that this trip would be harmful to my career. Now that I finally have time to reflect on this experience I realize that it is actually quite the opposite. You are probably wondering « how so? », let me tell you my story.</em></p><h3><strong>1. Good Relationship skills</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlxHSAc41HYKeyXdCWbEBA.jpeg" /><figcaption>The sulphurous Ijen volcan, Indonesia</figcaption></figure><p>When I was in China, I was totally lost in this huge country. Hopefully I met young Chinese in my guesthouse, they didn’t speak english so we communicated through images, hands, and the most important smiles. Thanks to them I had a lot of advices for my trip.</p><p>When you travel, you meet a lot of people. They are very different from your compatriots so you have to make efforts to be understood and to understand them. A good relationship skill is important because you are going to ask help many times. Even if you don’t speak their language, a smile and a caring attitude are your international passport to communicate with anybody. It’s not always simple, sometimes you are tired, have a lot of problems but you have to put all these things aside when you ask somebody for help.</p><p>It’s the same in a professional environment, having good relationship social skills is important for team working, conflict resolving, listening and in order to understand business needs.</p><blockquote>Except if you work alone in a cave you need this skill.</blockquote><h3><strong>2. Taste for challenge</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U7MjaIWyhTmHmPcZaDCDOg.jpeg" /><figcaption>Top of Rinjani Mount, Indonesia</figcaption></figure><p>When I was in Indonesia, I climbed many volcanos and amongst them the second highest of this huge archipelago, the Rinjani mount on Lombok Island.</p><p>These 3 days trek was one of my hardest challenges, 3 726 meters! The ascension to the peak at 3am, walking on a 70% sand slope. Pretty hard indeed.</p><p>At the sight of the sunrise, I had mixed feelings, somewhere between feeling proud and wondering :</p><blockquote>What’s my next challenge?</blockquote><p>You might have noticed that a lot a beautiful places are not easy to access when traveling. Going passed your own limits, physically speaking but most important mentally speaking. It is hard but definitely worth it!</p><p>In a company, the volcanos you need to clim are the challenges you have to reach. If you think about it you will realize it requires the same kind of skills, <strong>courage</strong> to surpass yourself, <strong>perseverance </strong>to not give up and <strong>discipline </strong>to keep on going forever and ever. You can get these skills set with sport challenges for instance or travelling.</p><h3><strong>3. Creativity</strong></h3><p>A great amount of problems happens when you travel. Sometimes they are critical, especially when you are on your own in the Gobi desert in Mongolia and you just had an accident which perforated your motorbike fuel tank. Hopefully I was just a slightly injured, but I couldn’t afford to keep on loosing gas. I found out that chewing gum could be a decent fix for the perforated fuel tank. Oh and I did not mention that my handlebar was twisted, so hopefully a few miles away I stubbled upon a mongolian farmer to help me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sbgy21dW7hTB0YlbqvDkoA.jpeg" /><figcaption>My lifesaver and his nephew, Mongolia</figcaption></figure><p>While traveling, because of the size bag you have to deal with limited means. That forces you to become ingenious.</p><p>As a web developper, I try to always be creative, to find the best solution to a each specific problem. It requires to <strong>think outside the box</strong>.</p><h3>4. Speaking several languages</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gaCKUiLVdbEoDL3PaVILzg.jpeg" /><figcaption>Great guide at <em>La Plantation, Cambodia</em></figcaption></figure><p>Arriving in India, I was so confused when I had to speak English with people. Thanks to my wonderful girlfriend, that gave me precious english lessons in a bus towards Rajasthan. With a lot of practice, I gain confidence in myself and I was not afraid anymore to speak english. I started more and more conversations and my level eventually improved.</p><p>Discussions are deeper than only basics sentences when you can actually communicate with locals, compared to superficial sentences learnt in your phrasebook. You can learn a lot more on the family system, the traditions of people met and their day by day life.</p><blockquote>Your trip is more intense when you connect with locals</blockquote><p>English should not be difficult for you if you read me. But learning a new language could be a great idea. Speaking foreign languages is a plus in the job market and it stimulates the whole brain. By learning a new language, you gain new perspective to solve problems.</p><h3><strong>5. Curiosity</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6XQJqjtUYCvp1F_WKFKkg.jpeg" /><figcaption>“Who is this stranger?” , Vietnam</figcaption></figure><p>I am curious by nature and this trip pushed my limits away. Museum, people habits, landscapes, sports, exotic food, etc… There are so many different things in this world that you should never be bored.</p><p>If I wasn’t curious, I would have missed a lot of things. I used to ask locals about what to see, to do, to taste… Each time I discovered things that I would never have found in a guide or on the web.</p><p>Being curious is also a strength when you work.</p><blockquote>Learning from someone else experience is extremely important.</blockquote><h3><strong>6. Be a source of proposals</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZrdQwxCWqEKDtvIzZKD0bQ.jpeg" /><figcaption>Crazy nightclub with money gun and trampoline, China</figcaption></figure><p>When<strong> </strong>you<strong> </strong>want go party on a Saturday night while being alone in a foreign country, you only have 2 options :</p><p>First, going alone and making friends there.<br>Second,<strong> </strong>convincing people from your hostel to go out with you<strong>.</strong></p><p>For my part I always try the second one first but convincing people is never easy. You have to propose something appealing enough for everyone, the more you experienced the more you know how to deal with people’s motivation.</p><h3>7. Adaptability</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0bb5wqbGOUsgvlLvUcOAEQ.jpeg" /><figcaption>“Just do it!”, Malaysia</figcaption></figure><p>Right away when you arrive in a new country, everything is different. You have to adapt fast to your new environment.</p><p>How should I behave to not come off as offensive to the locals? What are the do’s and the don’ts? These questions are necessary and your trip can be totally different if you don’t get along with locals customs.</p><p>Adaptability is a skill that allows you to be ready in any situation. We are living in a world that is constantly moving, being in phase with its evolution is primordial.</p><p>It’s even worst at work, new people hired, new ideas found, new organization set up all these speed up the change, so be ready and <strong>embrace it!</strong></p><blockquote>These skills are as important as your expertise in your job.</blockquote><blockquote>Improve them will help you in your career but also in your life.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZiggcYXzHX5qm1wnFdRS7w.jpeg" /><figcaption>“Goodbye!”, Laos</figcaption></figure><p><em>Thanks to </em><a href="https://www.instagram.com/shrabzus/"><em>shrabzus</em></a><em> for the proofreading !</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65fb9aa42d80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React + GraphQL = ❤]]></title>
            <link>https://medium.com/@FdMstri/react-graphql-e0c1ca714525?source=rss-d9ca5be78595------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0c1ca714525</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[webpack-2]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Fabien de Maestri]]></dc:creator>
            <pubDate>Tue, 28 Feb 2017 21:22:31 GMT</pubDate>
            <atom:updated>2017-03-02T11:49:42.622Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Sbfoc8u9fIfRSzyqxynwWQ.png" /></figure><p><em>This is the👌 third article from the series </em>“Build a Pokédex with GraphQL, React.js, Semaphore CI, Heroku and Docker”<em>.</em></p><h4>A quick recap from our previous chapters:</h4><ul><li>we built a <strong>GraphQL Server</strong></li><li>we fetched data from <strong>PokéApi</strong></li><li>we defined <strong>schemas</strong></li><li>we interacted via <strong>GraphiQL</strong></li><li>we wrote <strong>unit</strong> tests</li><li>we wrote <strong>integration</strong> tests</li></ul><p>If you haven’t read the previous chapter I will put the link below, so you can give it a look 👀.</p><p><a href="https://medium.com/@FdMstri/testing-a-graphql-server-13512408c2fb">Testing a GraphQL Server</a></p><h3>Webpack</h3><p>We use Webpack as build tool. Its main goal is to group all our client’s application files to process and produce a build file. Webpack allows us to easily managing our assets, (optimization of images, css file concatenation, minification…).</p><p>Install Webpack:</p><pre>npm i --save-dev webpack</pre><p>We use Webpack version 2 which brings variety of anticipated features, including native support for ES6 modules. Using of <strong>imports</strong> and <strong>exports </strong>makes possible <strong>tree-shaking optimization. “</strong><a href="https://medium.freecodecamp.com/tree-shaking-es6-modules-in-webpack-2-1add6672f31b#.q6u8hyysi">Tree-shaking is the ability to only include code in your bundle that is being <em>used.</em></a><em>”</em></p><blockquote><em>“If you wonder why it’s called tree-shaking: think of your application as a dependency graph, this is a tree, and each export is a branch. So if you shake the tree, the dead branches will fall.” — Roman Liutikov</em></blockquote><p>Learn more, with this article .</p><p><a href="https://medium.freecodecamp.com/tree-shaking-es6-modules-in-webpack-2-1add6672f31b">Tree-shaking ES6 Modules in webpack 2</a></p><p>Here the <em>webpack.config.js</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0c738d2d2270d3fe2c47edb932d4526/href">https://medium.com/media/a0c738d2d2270d3fe2c47edb932d4526/href</a></iframe><p>We define an entry and an output file, the bundle is required by the <em>index.html</em>.</p><p><strong>babel-loader</strong> is a Webpack loader, it parses all js and jsx files with babel. We configure babel with <strong>babelrc</strong> file.</p><p>Create a .babelrc in project’s root.</p><pre>touch .babelrc</pre><p>We configure babel to transpile jsx to js, and using last <strong>es2015</strong> features !</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75d922d9ee512d1705f9f36d989ca36b/href">https://medium.com/media/75d922d9ee512d1705f9f36d989ca36b/href</a></iframe><p>Then install all babel dependencies:</p><pre>npm i babel-core babel-loader babel-preset-es2015-native-modules babel-register --save-dev</pre><ul><li><strong>babel-core </strong>: Babel itself</li><li><strong>babel-loader</strong> : This package allows transpiling JavaScript files using <a href="https://github.com/babel/babel">Babel</a> and W<a href="https://github.com/webpack/webpack">ebpack</a>.</li><li><strong>babel-preset-es2015-native-modules</strong> : Babel preset for all es2015 plugins except babel-plugin-transform-es2015-modules-commonjs</li></ul><p>It remains some Webpack configuration, but we have to add some code.</p><h3>React Part</h3><p>Create an app folder and the react root file app.jsx.</p><pre>mkdir app &amp;&amp; cd app</pre><pre>touch app.jsx</pre><p>Install React and React-dom:</p><pre>npm i --save-dev react react-dom</pre><p>React-dom package makes a React element into the DOM in the supplied container. Here the container is a DOM element with the ‘app’ id.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8465e9d921a3aa59ccac4ba9294e302/href">https://medium.com/media/f8465e9d921a3aa59ccac4ba9294e302/href</a></iframe><p>Create an index.html with an app id. The template require the bundle.js generated by Webpack.</p><pre>cd app</pre><pre>touch index.html</pre><p>Copy-paste this content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7559e3e4f945f69ae64111b413765666/href">https://medium.com/media/7559e3e4f945f69ae64111b413765666/href</a></iframe><p>That index.html file should be moved in dist folder. We can use a plugin to copy this file to the dist folder. But we can be clever here. Thanks to the plugin <strong>html-webpack-plugin</strong>, the index.html should be moved in dist folder and the script automatically required, then we can pass an hash options to enable cache busting ! That plugin adds a query parameter to the dist file name, it’s different for each builds, thus browser see that the bundle has change.</p><p>Install <strong>html-webpack-plugin:</strong></p><pre>npm i --save-dev html-webpack-plugin</pre><p>Then add a <em>plugins</em> property to Webpack’s configuration with that code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*hDPHLi9X-FH_FLCRmSwOIA.png" /></figure><p>Don’t forget to require <strong>html-webpack-plugin</strong>. Now we can remove the require for the bundle.js, it’s useless now.</p><p>Pokedex.jsx is the main entrypoint of our React App, let’s create a first version.</p><pre>mkdir app/components &amp;&amp; cd app/components</pre><pre>touch Pokedex.jsx</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02d0c55db0ce6e3438df9acb332c37bd/href">https://medium.com/media/02d0c55db0ce6e3438df9acb332c37bd/href</a></iframe><p>Now we have to start Webpack and the node server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*Xvv83-u4j8M7hb0YhkepIw.png" /></figure><p>If you run npm run watch<strong>, </strong>the server will not be launched. This is because Webpack is in watch mode. The solution that I found it’s to run <strong>concurrently</strong> both commands, thus, each command can be launched. I’ve found <a href="https://www.npmjs.com/package/concurrently"><strong>concurrently</strong></a> module. If you have a better solution, please tell me in comments.</p><p>Install concurrently:</p><pre>npm i --save concurrently</pre><p>Here the final package.json</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/156246f74fcfff58cd851e28ff25a6f2/href">https://medium.com/media/156246f74fcfff58cd851e28ff25a6f2/href</a></iframe><p>The last step is to create a middleware in index.js to serve our static resources.</p><pre>app.use(express.static(&#39;dist&#39;));</pre><p>Now run</p><pre>npm run watch</pre><p>And browse <a href="http://localhost:3001/">http://localhost:3001</a> ! You should see a beautiful <strong>Hello World</strong> !</p><p>The Webpack part is over, we can start to code !</p><h3>React component</h3><p><strong>Pokedex.jsx</strong> has responsibility to fetch Pokémons and manage actions happening from arrows.</p><p>Create 3 void methods forming your skeleton of Pokedex.jsx:</p><ul><li><strong>makeRequest</strong> : Take a Pokémon id and call the GraphQL server</li><li><strong>arrowRight</strong> : Call makeRequest with an incremented id</li><li><strong>arrowLeft</strong> : Call makeRequest with a decremented id</li></ul><p>Create two buttons which bind <strong>arrowRight</strong> and <strong>arrowLeft</strong>. Implement each method.</p><p>Here a solution :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97266cd8403af7c99e28ebb686509997/href">https://medium.com/media/97266cd8403af7c99e28ebb686509997/href</a></iframe><p>We bind <strong>this</strong> on <strong>arrowRight</strong> and <strong>arrowLeft</strong> methods into constructor because they are used in render. To keep the current index, we save it in state.</p><p>This code closes of the final solution. We have to update <strong>makeRequest </strong>to fetch Pokémon and finally add some static components.</p><h4>Communicate with you GraphQL API</h4><p>Create a client folder and a getPokemon.js file.</p><pre>cd app</pre><pre>mkdir client &amp;&amp; cd client</pre><pre>touch getPokemon.js</pre><p>In this file we call our GraphQL server to fetch a Pokémon, it sends that request to grab a Pokemon :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*qmQiHESlCSoG9taJS6BRiw.png" /></figure><p>We create a <strong>getPokemon</strong> method taking Pokémon id, building the url, and return the request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb305e57bdc0554d5752a3820fe4d397/href">https://medium.com/media/bb305e57bdc0554d5752a3820fe4d397/href</a></iframe><p>I’ve choose <strong>superagent</strong> because it’s isomorphic, light and easy ! Now we can update Pokedex.jsx.</p><p>We have only one function so I’ve used <strong>export default.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8696ccb442fcc3d272ed54331aacb6b7/href">https://medium.com/media/8696ccb442fcc3d272ed54331aacb6b7/href</a></iframe><p>If you click on the right button you should receive a object, with a body property containing :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*J3Ecv_MISghtYSHK5ue0EQ.png" /></figure><p>Hourra ! 🎉🎉</p><h3><strong>React Components</strong></h3><p>The heart is now over, but it’s still very ugly.</p><p>Download this image and save it in a <strong>img</strong> folder. Rename that image in <em>Pokedex.png</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*HmJQ3auSA_TivUEALJNq1Q.png" /></figure><p>The main screen display the Pokémon <strong>sprite</strong>, the second its <strong>name</strong> and in right bottom corner its <strong>id</strong>. We browse Pokémons with arrows <strong>left</strong> and <strong>right</strong>.</p><p>A concrete example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*8LaXeS_KmhcTBx0yC_OR8w.png" /></figure><p>There is not many css. So I decided to test style in component. I recommend you to see the presentation given by Christopher Chedeau, <a href="https://speakerdeck.com/vjeux/react-css-in-js">React: CSS in JS</a>.</p><blockquote>Radium is a set of tools to manage inline styles on React elements. It gives you powerful styling capabilities without CSS.</blockquote><pre>npm install --save radium</pre><p>Radium support pseudo-class, media query, modifiers contrary to <strong>style inline</strong>.<strong> </strong>In addition CSS in JS gives us :</p><ul><li>Scoped styles without selectors</li><li>Dead code elimination</li><li>Highly expressive</li></ul><p>Set up Radium is not very hard, just export a Radium instance wrapping your class.</p><p>Write your style in an object, and access property in`style`tag. Example with the Pokédex image save previously:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5acc588fea0e1475081bc78adc6d9b21/href">https://medium.com/media/5acc588fea0e1475081bc78adc6d9b21/href</a></iframe><p>Make <strong>img</strong> directory public:</p><pre>app.use(express.static(&#39;img&#39;));</pre><p>We have 4 React components left. These components are stateless and functional. They are plain JavaScript functions with return containing the DOM element. Simpler than Class, there are no lifecycle methods, no state to manage or constructor. Functional components are greater performance, bigger testability and bigger readability than class. I encourage you to multiply stateless components and put logic in higher component.</p><h4>Paddle : Left and Right buttons</h4><p>Manage buttons.</p><pre>cd app/components</pre><pre>touch Paddle.jsx</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6f18dc01f072baa667349d104b4178f/href">https://medium.com/media/e6f18dc01f072baa667349d104b4178f/href</a></iframe><h4>DetailInfo.jsx</h4><p>Display the Pokémon order.</p><pre>cd app/components</pre><pre>touch DetailInfo.jsx</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f793d0bd38d42d7a21d5c969591d783/href">https://medium.com/media/3f793d0bd38d42d7a21d5c969591d783/href</a></iframe><h4>ScreenInfo.jsx</h4><p>Display the Pokémon name</p><pre>cd app/components</pre><pre>touch ScreenInfo.jsx</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ff105f085bb33bc03543518cb325516/href">https://medium.com/media/2ff105f085bb33bc03543518cb325516/href</a></iframe><h4>Screen.jsx</h4><p>Display the Pokémon sprite.</p><pre>cd app/components</pre><pre>touch Screen.jsx</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3da80e29fe2af1348eb55e75e93734e4/href">https://medium.com/media/3da80e29fe2af1348eb55e75e93734e4/href</a></iframe><p>All components are writen, we have to compose them in the main class.</p><h4>Pokédex.jsx</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdd220a5fab56764caa4ad190a5bb2db/href">https://medium.com/media/bdd220a5fab56764caa4ad190a5bb2db/href</a></iframe><h3>Conclusion</h3><p>We have seen how making a front-end with React.js, using a build tool with Webpack and coupled with a GraphQL API. 🤙</p><p>I hope it wasn’t too hard, and I hope to see you on my next episodes ! The code is available on branch <a href="https://github.com/zgababa/testpokereact/tree/Chapter3">Chapter3</a> of Github.</p><p>Please tell me, if you see something to improve ! 🕵️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0c1ca714525" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My secret morning]]></title>
            <link>https://medium.com/@FdMstri/my-secret-morning-6ef533e4d677?source=rss-d9ca5be78595------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ef533e4d677</guid>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[morning-routines]]></category>
            <category><![CDATA[morning]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Fabien de Maestri]]></dc:creator>
            <pubDate>Tue, 14 Feb 2017 18:51:32 GMT</pubDate>
            <atom:updated>2017-02-15T13:08:57.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*ecb_xaB_wzErupr5kQDQoQ.jpeg" /></figure><p>Each morning I stand up at 7H30 not to go work but to begin my morning routine.</p><p>This is inspired from the <a href="https://www.amazon.com/Miracle-Morning-Not-So-Obvious-Guaranteed-Transform/dp/0979019710/ref=sr_1_1?ie=UTF8&amp;qid=1457391440&amp;sr=8-1&amp;keywords=miracle+morning">Miracle Morning</a> of <em>Hal Elrod</em>. In the book the author explains how we can <strong>wake up earlier</strong> each morning. Why is it useful to wake up earlier ? Let’s discover my typical morning.</p><h3>Morning routine</h3><p><strong>7H29</strong> : …</p><p><strong>7h30 :</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FNwz6NZkToYC4M%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fjuly-great-Nwz6NZkToYC4M&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FNwz6NZkToYC4M%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="333" frameborder="0" scrolling="no"><a href="https://medium.com/media/83c4a2bf10292e51479a85a42ea589fa/href">https://medium.com/media/83c4a2bf10292e51479a85a42ea589fa/href</a></iframe><p>DRING ! DRING !</p><p>I get up fast to switch off my alarm clock which is deep in my room.</p><p>I catch a glass full of water. And I sit down on my chair to start a ten minutes meditation.</p><h3>7h30 : Meditation</h3><p><strong>Meditation</strong> makes me keep my calm in many life situations. I breath deeply to relax my body and my spirit. For example, it was useful when I passed a driving exam. French motorcycle driving exam is a very hard and stressful exercice, it contains many hard steps. You have to stay focus, because if you loose your focus the motorcycle can fall.</p><p>So the driving exam day, I was breathing very deeply to expulse my stress and up my focus. Thanks to that I succeeded reducing my fear and I got my motorcycle driving exam :).</p><blockquote>Breathing concentration is a powerful tool !</blockquote><p>During those <strong>10</strong> minutes of meditation I am totally connected to my body, and it’s good to have a little peace before begin an intense day.</p><h3><strong>7h40</strong>: Reading my affirmations</h3><p>Affirmations are short sentences describing an objective and steps to achieve it. Example :</p><blockquote><strong>I choose to become</strong> a sprinter faster than Bolt <strong>so I decide</strong> to go training at 9 a.m every day.</blockquote><p>Reciting those affirmations <strong>every</strong> morning makes me have my current step clear in my mind. My actions tend consciously or not toward my goals.</p><p>For example I have this affirmation :</p><blockquote><strong>I choose to become</strong> an athlete, <strong>so I decide</strong> to go Crossfit training 5 days per week at 9 a.m every day.</blockquote><p>My affirmations describe objectives, which are part of a global objective that we can call a dream. So reciting my affirmation everyday, makes me closer of the achievement of my dreams. It increases my will to sweat each morning :)</p><p>If you want affirmations more effective. Follow this advice :</p><blockquote>Be straight and have loud voice filled with confidence !</blockquote><h3><strong>7h45</strong>: Visualization</h3><p>I imagine myself completing an objective and its associated steps.</p><p>It’s the perfect affirmations additional, more the story seems consistent more you achieve quickly your dreams !</p><blockquote>I close my eyes and I see me overtake Bolt at J.O. Then I see each step to achieve this, me going to training at 9 a.m every day, eating not much…</blockquote><blockquote>“There is no favorable wind for someone who does not know where he is heading”. Seneca</blockquote><h3><strong>7h50</strong>: Writing</h3><p>In a diary, I wrote my fears, my success, what I need to improve and some problems. It let my head free : it’s a kind of like writing a “todo list”, it’s very pleasant.</p><p>This morning I wrote the problems that happened the day before. I’m <br>conscious of those problems, and today I won’t reproduce them.</p><blockquote>Take time, analyse your problems and resolve them.</blockquote><h3><strong>8h30</strong>: Sport</h3><p>After eating and dressing up I go to <strong>Crossfit</strong>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FsiaX1NJz2GSJi%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2Fmiracles-siaX1NJz2GSJi&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FsiaX1NJz2GSJi%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="247" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2b4b070842cf3131e62b87cf266e3d9/href">https://medium.com/media/b2b4b070842cf3131e62b87cf266e3d9/href</a></iframe><p>This is hard, very hard. But after an intense <em>Workout Of the Day</em> I feel very, <strong>very good</strong>. A good shower complete this intense morning.</p><h3>Conclusion</h3><p>Thanks to this routine I’m ready to complete all my day’s challenges ! My body is in good shape and my health follows him.</p><p>Have you already tested this type of morning ?</p><p>Have you any comments about that ? Please let my know 🕵️</p><p>See you ! 🤘</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ef533e4d677" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing a GraphQL Server]]></title>
            <link>https://medium.com/@FdMstri/testing-a-graphql-server-13512408c2fb?source=rss-d9ca5be78595------2</link>
            <guid isPermaLink="false">https://medium.com/p/13512408c2fb</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Fabien de Maestri]]></dc:creator>
            <pubDate>Mon, 06 Feb 2017 13:37:17 GMT</pubDate>
            <atom:updated>2017-02-06T18:55:08.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*58wtIIuxK7AOV0NBXVCOug.jpeg" /></figure><p><em>This is the ✌️ second article from the series </em>“Build a Pokédex with GraphQL, React.js, Semaphore CI, Heroku and Docker”<em>.</em></p><h4>A quick recap from our first chapter :</h4><ul><li>we build a <strong>GraphQL Server</strong></li><li>we fetch data from <strong>PokéApi</strong></li><li>we define <strong>schemas</strong></li><li>we interact via <strong>GraphiQL</strong></li></ul><p>If you haven’t read the first chapter i will put the link below, so you can give it a look 👀.</p><p><a href="https://medium.com/@FdMstri/build-a-graphql-server-and-catch-em-all-af7a8f3bc111">Build a GraphQL server and Catch ‘Em All !</a></p><p>Now comes the <strong>important</strong> step, testing! Of course, you alway test your code…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl0O9zareSGZoeC7gk%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2Fjerry-seinfeld-curb-your-enthusiasm-larry-david-l0O9zareSGZoeC7gk&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl0O9zareSGZoeC7gk%2F200.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b17d194a3719e0fc94b28f265a769b8/href">https://medium.com/media/5b17d194a3719e0fc94b28f265a769b8/href</a></iframe><p>Integration testing will focus on testing end-to-end of a GraphQL queries.</p><h3>Unit testing</h3><p>This type of test is particularly important because it allows us to see regressions in our schema, test complex resolve methods and function calls.</p><p>We are going use</p><ul><li><a href="https://mochajs.org/">Mocha</a> as a <strong>test runner</strong> framework</li><li><a href="http://chaijs.com/">Chai</a> for our assertion<strong> framework</strong></li><li><a href="http://chaijs.com/guide/styles/#expect">Expect</a> for our assertion<strong> style</strong></li><li><a href="http://sinonjs.org/">Sinon</a> for our <strong>stub</strong> framework</li><li><a href="https://github.com/domenic/sinon-chai">Sinon-chai</a> to assert sinon stub with chai <strong>assert style</strong></li><li><a href="https://www.npmjs.com/package/babel-register">babel-register</a> to use babel in our tests</li></ul><pre>npm i --save-dev mocha<br>npm i --save-dev chai<br>npm i --save-dev sinon<br>npm i --save-dev sinon-chai<br>npm i --save-dev babel-register</pre><p>In your <strong>package.json</strong>, add a script command to “scripts” that will launch our tests. It should look like this:</p><pre>&quot;scripts&quot;: { <br>  &quot;test-server&quot;: &quot;mocha schema/**/*.serverSpec.js&quot;<br>}</pre><p>Mocha now run tests on all *.serverSpec files in schema folders.</p><p>We going to add test for our Pokémon resource.</p><p>Create a <em>pokemon.serverSpec.js </em>in <em>schema/pokemon</em>, then launch with:</p><pre>npm run test-server</pre><p>If you see that, we can continue 👏.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*DpfGMFNB1Q8dt8pPupEDlA.png" /></figure><h4>Test Schema Fields</h4><p>To tests types, we need the resource Pokemon, Chai &amp; expect.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e446de508cb7283941967d525911bd96/href">https://medium.com/media/e446de508cb7283941967d525911bd96/href</a></iframe><p>To test a field, we need to test if a schema field exists and if its GraphQL Type is correct.</p><p>For example, this is how we would test for type String on an id field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*3FQAYMxqQ-B63BD4NTICSg.png" /></figure><p>We call the GraphQL getFields method which should return our schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*jOPzdYkv_kB7HpgYvkqPVw.png" /><figcaption>Return of pokemonType.getFields()</figcaption></figure><p>We can easily run our tests with the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/571cbb2686e20a1f2d2040132df41ca9/href">https://medium.com/media/571cbb2686e20a1f2d2040132df41ca9/href</a></iframe><p>That’s all👌.</p><p>These tests <strong>avoid regressions</strong> in your schema. Regressions can happens when someone else modify the code like GraphQL Type.</p><p>In our example we have basic <strong>Scalar Types</strong> like <em>GraphQLString</em> and <em>GraphQLInt</em> but its not very different to do the same thing for composed or custom resources. Here’s and example using a custom gender type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*IvT7OGdqciQeFDwftJWi3g.png" /></figure><p>And here is how we would test it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*De33IZ1nm_aIb20q3mfWBQ.png" /></figure><h4>Testing Resolvers</h4><p>To test the resolver, you would do the same thing. We have access to resolve function with the same <em>getFields</em> method we used previously.</p><p>We create another field with a <strong>custom resolution</strong>. It will be more interesting than <em>img</em> resolve field.</p><p>The field orderFormatted add an “# ” front of order number. If no order number is provided, it return an empty string.</p><p>Here <em>orderFormatted </em>in <em>pokemon.js</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df8753fbf8453ffcf938153902901cbb/href">https://medium.com/media/df8753fbf8453ffcf938153902901cbb/href</a></iframe><p>First make a test for orderFormatted type like previous, next we test the resolve of orderFormatted.</p><p>Let’s call <em>getFields </em>with a value in resolve, and expect its result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*Nu_Q9qRKp065WcGWEyeAZQ.png" /></figure><p>Now we test when no order is provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*pBoB_UEem79wvkLiWjT2rQ.png" /></figure><p>If you’re resolve is a <strong>Promise</strong> you have to return the resolve and <strong>expect in</strong>. Like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*pe7hZcRz23Blez6ZwxYVbw.png" /></figure><p>Here, the code of resolve tests only.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf16d55bcff4d4021ff14a657eefb3f1/href">https://medium.com/media/cf16d55bcff4d4021ff14a657eefb3f1/href</a></iframe><h4>Resolve resource</h4><p>Comes the final part of this Unit Testing part, we test now the resolve resource function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*1Sl6vEtfis2kgFMfnoewsA.png" /></figure><p>We have two different tests for the resolve function here :</p><ul><li>If we have an <em>id</em> argument it calls <em>client.getPokemon </em>with <em>id</em> argument</li><li>Any else it calls <em>client.getPokemons</em></li></ul><p>We need to stub <em>getPokemon</em> and <em>getPokemons,</em> let’s create a sandbox.</p><pre>const sandbox = sinon.sandbox.create();</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a492ed9fc499f68c5efa2c5f6952005b/href">https://medium.com/media/a492ed9fc499f68c5efa2c5f6952005b/href</a></iframe><p>Then we just need to test the call of these methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0d4ef89ae71e04d348ec8af243315f8/href">https://medium.com/media/b0d4ef89ae71e04d348ec8af243315f8/href</a></iframe><h3>Integration testing</h3><p>Integration tests allow you to tests all your API. They are very important, it’s the only way to be truly confident on your code, when you have complete your unit test.</p><p>Steps are :</p><ul><li><strong>Init</strong> a Express server with GraphQL</li><li>Call GraphQL with a <strong>query</strong></li><li>Expect the <strong>status cod</strong>e, and the <strong>response</strong></li></ul><p>For the integration server I propose this code, if you see a better way, please tell me :) I put this code in a directory <em>utils</em> at root.</p><p>The <strong>start </strong>method create an Express app with GraphQL, the <strong>close </strong>method close the server.</p><p><strong>graphqlQuery </strong>make<strong> </strong>a request on the integration server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa2973848fe66628de3e9df3190e8e3a/href">https://medium.com/media/fa2973848fe66628de3e9df3190e8e3a/href</a></iframe><p>Now we have our integration server we can make integration tests on it. 🙃</p><p>Start and close the integration server <strong>before</strong> and <strong>after each </strong>tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29da5751f90782b173147cec594486ae/href">https://medium.com/media/29da5751f90782b173147cec594486ae/href</a></iframe><p>For the first integration test, we are going to test the fetch of a specific Pokémon. We have just to precise the query and its response.</p><p>The query :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*lPMVzbxO3HgjZ9w3o2PAXA.png" /></figure><p>The expected :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*qJeAZ_Lf2laCJAZoFA5Dmg.png" /></figure><p>We call <em>graphqlQuery </em>to do the request. When the request is executed, we expect its status code and result. We do the same for <em>pokemons </em>query<em>.</em></p><p>Finally we launch integration tests with a <strong>different command</strong>, because we launch an integration server. Thank to that if you choose to specifically run your unit tests, it will be faster. 💃</p><pre>“test-integration”: “mocha ‘schema/**/*.integration.spec.js’”</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf44c0a616a75296b2adf33475b03719/href">https://medium.com/media/bf44c0a616a75296b2adf33475b03719/href</a></iframe><h3>Conclusion</h3><p>I hope you enjoyed this article, I am open to accept feedback or contributions, and if you liked it, recommend it to a friend, share it or read it again 📖, or just comment below.</p><p>You can retrieve the final code, in this <a href="https://github.com/zgababa/testpokereact">repository</a> on the branch <a href="https://github.com/zgababa/testpokereact/tree/Chapter2"><strong>Chapter2</strong></a></p><p>I would <strong>thank you </strong>very much <a href="https://medium.com/u/59796b5f7b2e">Enso</a> for his re-reading of my english 👍</p><p>And finally let me remember you, this article is part of “<em>Build a Pokédex with GraphQL, React.js, Semaphore CI, Heroku and Docker</em>” series so, next week I will publish another chapter of this series.</p><p>Until next time you can <strong>follow</strong> me at twitter @<a href="https://twitter.com/FdMstri">FdMstri</a> 😎</p><p>Bye !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13512408c2fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a GraphQL server and Catch ‘Em All !]]></title>
            <link>https://medium.com/@FdMstri/build-a-graphql-server-and-catch-em-all-af7a8f3bc111?source=rss-d9ca5be78595------2</link>
            <guid isPermaLink="false">https://medium.com/p/af7a8f3bc111</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Fabien de Maestri]]></dc:creator>
            <pubDate>Mon, 23 Jan 2017 13:35:48 GMT</pubDate>
            <atom:updated>2017-02-03T16:42:51.451Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*bFesKGzuoNlP6Ima7ObY5g.png" /><figcaption>Your future Pokédex !</figcaption></figure><p><em>I created this project </em><a href="https://poke-react.herokuapp.com/"><em>https://poke-react.herokuapp.com/</em></a><em> to introduce GraphQL, but progressively he became a test project where I played with technologies like React, </em><a href="http://semaphoreci.com/"><em>Semaphore</em></a><em> (Continous Integration), Heroku or yet Docker. I propose to (re)code this Pokédex with me :)</em></p><p>Today we build the server part with GraphQL !</p><p>If you don’t know what GraphQL is, see these resources :</p><ul><li><a href="http://graphql.org/learn/">http://graphql.org/learn/</a></li><li><a href="https://learngraphql.com/">https://learngraphql.com/</a></li><li><a href="http://fr.slideshare.net/FabiendeMaestri/lets-graph">http://fr.slideshare.net/FabiendeMaestri/lets-graph</a> (My presentation given in Paris Node.js Meetup)</li></ul><h4>Basic http server :</h4><p>Let’s make a very basic express server running on port 3001.</p><pre>npm i  --save express</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/421943e1bd3e7e5f32c7061faf66d529/href">https://medium.com/media/421943e1bd3e7e5f32c7061faf66d529/href</a></iframe><p>Then we are going to add some GraphQL resource to fetch pokemons from <a href="http://pokeapi.co/api/v2/">PokéApi</a>.</p><p>It’s a REST API totally free to use, but you can donate to support <a href="https://pokeapi.co/">them</a>.</p><p>We can fetch for pokemons with this route<em> /</em><a href="http://pokeapi.co/api/v2/pokemon-form/"><em>pokemon-form</em></a><em>. It’s limited at twenty results per page.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*LIHHR5fVgpy1lrk1571MXw.png" /><figcaption><a href="http://pokeapi.co/api/v2/pokemon-form/">http://pokeapi.co/api/v2/pokemon-form/</a></figcaption></figure><p>We can fetch for a specific Pokemon with an id, example with Butterfree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9PC9G4Q-w2-Ie-rZ_9M8Q.png" /><figcaption><a href="http://pokeapi.co/api/v2/pokemon-form/12/">http://pokeapi.co/api/v2/pokemon-form/12/</a></figcaption></figure><p>Let’s begin by fetch a specific Pokemon. For our Pokédex we need these fields :</p><ul><li>id : <em>String</em></li><li>name : <em>String</em></li><li>order : <em>Integer</em></li><li>img (sprites.front_default) : <em>String</em></li></ul><p>Create a file pokemon.js in folder /schema/pokemon. That will be our pokemon GraphQL type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e357800dc156e8465509f474899df8d3/href">https://medium.com/media/e357800dc156e8465509f474899df8d3/href</a></iframe><p>We can add an <em>id</em> argument to fetch a particular Pokemon. In the resolve function, we return a mock for now.</p><p>Here our pokemon resource :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe25ad033a40996e7a638f5f7bded709/href">https://medium.com/media/fe25ad033a40996e7a638f5f7bded709/href</a></iframe><h4>The Root Schema</h4><p>The rootSchema contains all types which can be reached in root of a query</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*by4t-OBtQ_ML87bKYyo9FA.png" /></figure><p>Here pokemon can be called directly, but not version because it’s not in root schema.</p><p>Create <em>rootSchema.js </em>in<em> shema </em>directory</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac9a3e3800e0344bd0884d3076b56c13/href">https://medium.com/media/ac9a3e3800e0344bd0884d3076b56c13/href</a></iframe><h4>Express + GraphQL</h4><p>We want access GraphQL by the endpoint <em>/graphql </em>and pass the query with the query param <em>graphqlQuery .</em></p><p>So with Express we make a GET route, and we test the presence of our query param, else we return a 500.</p><p>Then we process the query with GraphQL.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3802cd09043bac35db4e1ae1c8c5152/href">https://medium.com/media/f3802cd09043bac35db4e1ae1c8c5152/href</a></iframe><p>Let’s try our server and install graphql :</p><pre>npm install —-save graphql</pre><pre>node index.js</pre><p>Browse this <a href="http://localhost:3001/graphql?graphqlQuery=%7B%0A%20%20pokemon%20%7B%0A%20%20%20%20id%0A%20%20%20%20name%0A%20%20%20%20order%0A%20%20%20%20img%0A%20%20%7D%0A%7D%0A">url</a>. You should see your mock :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*Q803CPBxGCjz5_9OVJ3tPw.png" /></figure><p>It’s not very easy to interact with a query url, so we are going to add GraphiQL</p><p>GraphiQL is an interface to interact with graphQL. You have access to autocompletion, schema introspection, variable interaction with query…</p><pre>npm install --save express-graphql</pre><p>Plug with your server on <em>/graphiql </em>endpoint.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e84cb4f4ea9bd742fa1b5c0cbb4aebc/href">https://medium.com/media/7e84cb4f4ea9bd742fa1b5c0cbb4aebc/href</a></iframe><p>Now you can browse <a href="http://localhost:3001/graphiql">http://localhost:3001/graphiql</a> and play with your api.</p><p>Type your query, and validate with play button or cmd + enter (mac user)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kur4fvV7u1ele7k0NIwC7Q.png" /><figcaption>It works !</figcaption></figure><h4>No more mocks</h4><p>It’s cool, but mocks are for babies ! We want to connect with the pokéapi.</p><p>Create a <em>pokemon.client.js </em>in pokemon folder, and install <a href="https://github.com/request/request-promise">request-promise</a> to make requests with Promise support. Resolve function in graphQL should always return Promise to not block resolution of other fields.</p><p>In graphQL, resources on the same level are resolved in parallel and sub-resource sequentially. For example :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*eb1j4qwngAyz2jJnLH17CQ.png" /><figcaption>GraphQl request</figcaption></figure><p>Of course it’s not required for immediate resolution. Like</p><pre>Promise.resolve(`# ${pokemon.order}`)</pre><p>We can install request-promise and also bluebird :</p><pre>npm install --save request<br>npm install --save request-promise<br>npm install --save bluebird</pre><p>We have to expose a method to request the pokéapi with an id. Remember the url was <a href="http://pokeapi.co/api/v2/pokemon-form/1/">http://pokeapi.co/api/v2/pokemon-form/:id/</a>.</p><p>getPokemon takes an id, request the api and return a promise.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8de281d29c188b91919f03de1579e9d8/href">https://medium.com/media/8de281d29c188b91919f03de1579e9d8/href</a></iframe><p>Remplace the mock by getPokemon in <em>pokemon.js</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dccb216f115592ec6a22da62f079de5c/href">https://medium.com/media/dccb216f115592ec6a22da62f079de5c/href</a></iframe><p>Don’t forget to pass an id at you query :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kzKQ1a2ROFZj-M6iqN6ExQ.png" /><figcaption>It works :)</figcaption></figure><h4>Catch them all !</h4><p>Alright, now we want a set of pokemon. In the rootSchema, create a pokemons type. That will be a list of pokemon type, args are not necessary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*E20zje75FZsAS6mW5tEMZw.png" /></figure><blockquote>If it’s the same type, how can I distinguish <em>pokemon</em> or <em>pokemons ?</em></blockquote><p>In the resolve ! With the presence of an id param.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*VCGyBIUWUfaPbqMwM0isrQ.png" /></figure><p>I use <a href="https://www.npmjs.com/package/lodash.get">get</a> from <a href="http://lodash.com/">lodash</a>. It prevent you to access a child property of undefined parent, very useful.</p><pre>npm install --save lodash.get</pre><p>Just add getPokemons to your client, and everything will be ok !</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/300756d7bbe8dd0ead7e9f229d288919/href">https://medium.com/media/300756d7bbe8dd0ead7e9f229d288919/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BfJ68YEFTVoXIAPz0zzCA.png" /></figure><h3>Conclusion</h3><p>So we have an API, allow us to list pokemons or find a specific one. Next step is to learn how to test GraphQL.</p><p>Then we add a front with React :)</p><p>See you there !</p><p><em>Source here</em> : <a href="https://github.com/zgababa/testpokereact">https://github.com/zgababa/testpokereact</a> on branch <strong>Chapter1</strong></p><p><em>Source final here</em> : <a href="https://github.com/zgababa/PokeReact">https://github.com/zgababa/PokeReact</a></p><p><em>P.S Sorry for my english, I’m french. Don’t hesitate to correct me in comments :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af7a8f3bc111" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>