<?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 Sara Vieira on Medium]]></title>
        <description><![CDATA[Stories by Sara Vieira on Medium]]></description>
        <link>https://medium.com/@nikkitaftw?source=rss-b384aa92a080------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5SDOqSZIFIWJWvCeoVqnHw.jpeg</url>
            <title>Stories by Sara Vieira on Medium</title>
            <link>https://medium.com/@nikkitaftw?source=rss-b384aa92a080------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 13 Nov 2026 21:21:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikkitaftw/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[Living in the shadow of yourself — Dealing with low self-esteem in the public eye]]></title>
            <link>https://medium.com/@nikkitaftw/living-in-the-shadow-of-yourself-dealing-with-low-self-esteem-in-the-public-eye-c592e704b1f4?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/c592e704b1f4</guid>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Sat, 18 May 2019 13:37:38 GMT</pubDate>
            <atom:updated>2019-06-04T13:48:28.291Z</atom:updated>
            <content:encoded><![CDATA[<h3>Living in the shadow of yourself — Dealing with low self-esteem in the public eye</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIWxT6PHEBMji-OczDArlQ.jpeg" /><figcaption><em>Photo by </em><a href="https://unsplash.com/photos/fDxDWB7tUUE?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText"><em>Elti Meshau</em></a><em> on </em><a href="https://unsplash.com/search/photos/shadow?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText"><em>Unsplash</em></a></figcaption></figure><p><em>I wanna start by saying I am aware I am not famous ffs I just wanted a really deep title for this article.</em></p><p>For as long as I can remember I have low self-esteem and so do many people, it’s a common thing to have. Millions of people live with this every day, they don’t see anything good when they look at themselves and they wish they did.</p><p>I always suffered from this, it’s been a constant in my life for as long as I can remember but it only became crippling in the last two years or so.</p><h3>WTF do you mean by low self-esteem?</h3><p>In really simple terms it means you wake up every day not liking what you have become, wishing you were taller, stronger, better. It’s waking up wishing you could see in yourself other people see in you.</p><p>It also doesn’t mean you think you suck at everything, I know I am good at some things, like English. I am proud of the fact that several people have thought I was American. It means you don’t see anything good besides the small good things.</p><p>Most of the times people assume low self-esteem is mostly a physical thing, you hate your nose or you could wish you would lose some weight but not always. In my case, most of my low self-esteem issues are in terms of personality, I just think I am boring, that there is nothing interesting to know in me. This obviously takes a toll on your physical appearance because you stop caring, in your head, there’s no point right?</p><p>As you can see it ends up being a vicious cycle.</p><blockquote>“You are an inspiration”</blockquote><p>This is where the public eye starts. I have as pretty much like any other women in tech gotten shit in DM’s, YouTube or something else but that’s not usually the ones that get me thinking I suck. It’s actually the good ones, the ones that see things in me I could never see, those are the ones that make me feel like I am a fraud, that I am fooling these people.</p><p>I feel like I live in the constant fight to be what people think I am, to be someone I never saw myself being. To me, I am still a failure, not so much professionally but personally. I feel like if only I could be what some people think I am then I will be happy, then I will have it figured out and I will be okay.</p><p>I’m a code monkey who lives alone and orders take out a fuck ton. That’s all I see in me.</p><p>Sometimes I avoid meeting people I know online because I am scared this will unmask me as this really not cool human being, I’m scared I will be rejected by these human beings. That I won’t be the idea of me they have. It’s very easy for me to feel rejected by someone so in my head, it’s better to just avoid it and if I avoid it then they will still have the idea of me and not the real one.</p><p>Sometimes I don’t look at social media and I want to close everything because I know/think everyone in there doesn’t care about the real me, wtv the fuck that means.</p><h3>What about hate?</h3><p>I have gotten hate, a random dude once told me people like me are the reason Trump got elected and to this day I am trying to understand that but besides the point.</p><p>Its weird hate doesn’t get to me that much but I was hated and bullied for several years, I was gay in a Catholic high school, I made a thick skin.</p><p>I can take most types of random hate and shrug it off as nothing happen and sometimes even learn something from that.</p><p>I can’t do that with the opposite. I will always assume you like me because you don’t know me.</p><p>As for my deep posts here is a meme</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*6YsLRHYkUSWg5mSCdVsRWQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c592e704b1f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create custom GraphQL types]]></title>
            <link>https://medium.com/yld-blog/create-custom-graphql-types-999f009d3f46?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/999f009d3f46</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 11:26:04 GMT</pubDate>
            <atom:updated>2019-03-08T18:57:30.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9wHrewC1Dyf2Au_qEqwWcg.jpeg" /></figure><p>One good thing about <a href="https://www.yld.io/speciality/graphql/">GraphQL</a> is having control over how our schema and our return values from an API will look like. We can type everything and make sure that if we say something is a string and it’s not we will get an error.</p><p>That is amazing for having way more confidence in our code and in what comes back from the backend but by default GraphQL only ships with some basic types.</p><p>At the moment the basic types that ship with GraphQL are:String, Int, Float, Boolean,ID and even though all these types are very useful they do not cover everything we want to do in our API. Let’s say we have a list of images returned from an API in GraphQL, we can test if it’s a string but it may be a string that’s not actually an image and we will be showing a broken image to our users.</p><p>In this article let’s go over how to create what is called a Scalar type in GraphQL which is basically just a fancy term to say we are creating a new type we can use in our Schema.</p><h3>Creating the server</h3><p>I’m gonna use the Apollo Server 2 to get us to create a simple GraphQL server and if you want to follow along you can do by forking this <a href="https://codesandbox.io/s/apollo-server">sandbox</a> or by starting locally.</p><p>To start locally you will need to install apollo-server ,graphql and nodemon so you will need to run:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51011c584573bbcc845501d9fa9e07e8/href">https://medium.com/media/51011c584573bbcc845501d9fa9e07e8/href</a></iframe><p>After that create a package.json and add the following lines:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c238695d6a3af68cfa8e22679ddfcb2d/href">https://medium.com/media/c238695d6a3af68cfa8e22679ddfcb2d/href</a></iframe><p>Now we can start coding our GraphQL server and in my case, I will only have a Schema with two values: image and notImage so we can test our custom scalar.</p><p>So our index.js should be something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/208249d8fb9470af1ea795b26de5ebce/href">https://medium.com/media/208249d8fb9470af1ea795b26de5ebce/href</a></iframe><p>if you now run npm start you will see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qFc-oIIx1Nun9W-E_3z7XA.png" /><figcaption>GraphQL Playground with our two values</figcaption></figure><p>As you can see we have two values, they are both strings so GraphQL doesn’t care if it’s an image or not but we do so let’s start writing our custom scalar.</p><h3>Writing your custom scalar</h3><p>What our custom scalar will do is test if our link is actually an image and one way we can do that is to simply check if the link ends in an image extension but as you may imagine there are a lot of those so we are gonna use a tiny library that contains most of these file extensions and you can find on <a href="https://www.npmjs.com/package/image-extensions">npm</a>.</p><p>After installing it let’s start writing our function that will test if a value is actually an image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cdcac2e12c5e5e8d29486d0ee00d898/href">https://medium.com/media/4cdcac2e12c5e5e8d29486d0ee00d898/href</a></iframe><p>What we are doing here is getting the image extension with path.extname and removing the first character as that is the dot. After this, we see if the extension we get back is part of the known image extensions and if so we return the value given to us otherwise we return null.</p><p>Our function is done and now we need to actually create our custom scalar and for that, we need the function GraphQLScalarType from graphql and then create a new GraphQLScalarType and for that, we need a couple of things.</p><ul><li>Name — The name of our type and in my case, I will name it image.</li><li>Description — This is where you create a small description of what your type validates.</li><li>serialize — This function receives the value we receive in our GraphQL query and this is where we do the actual validation to check if the value is an image. If it is you can return the same value and if not we should return an error that explains to the user what happened. This is the only mandatory function.</li><li>parseValue — This function is the first one we get and it serves the idea of allowing us to clean out our value and serve it as we want to the serialize function.</li><li>parseLiteral — Serves the same point as parseValue but this one receives the AST and not just the value so it also gives you access to things like what kind of value it is.</li></ul><p>The parseValue and parseLiteral functions are needed if your Scalar is also an input type.</p><p>In our case, we are going to use the serialize function to see validate our value but the same principles of validation apply to all of them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/249914a913bd27f05bcaaf98d76f1da2/href">https://medium.com/media/249914a913bd27f05bcaaf98d76f1da2/href</a></iframe><p>As you can see we assigned our Scalar to a constant and instantiated the GraphQLScalarType class.</p><p>As for the name I called it Image and gave it a small description and as for the serializer function I get the value and run that value through our isImage function that will either return the value back to the user or return null.</p><p>In order to use our custom scalar, we need to do two things first.</p><p>We need to define it in our Resolvers like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3aa74cbeb498b2b6be8df14cd286def6/href">https://medium.com/media/3aa74cbeb498b2b6be8df14cd286def6/href</a></iframe><p>And also call it at the beginning of our type definitions like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06892277942c95568c87fd97c80c0dc9/href">https://medium.com/media/06892277942c95568c87fd97c80c0dc9/href</a></iframe><p>If you now try to run our query you will get null in the notImage like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7W9DBXJ50PwtXznMxf7rQA.png" /></figure><h3>Adding Errors</h3><p>This is all good and we now don’t return the value but it would be better if we could return an error that would explain to the user why that value didn’t come back.</p><p>We can do that by importing GraphQLError from the graphql package and use it as we would use the Error function in JavaScript.</p><p>Instead of returning null let’s now throw the error in our isImage function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db50d1a94bab2571dd806b02418099fd/href">https://medium.com/media/db50d1a94bab2571dd806b02418099fd/href</a></iframe><p>If you now try to run the exact same query you will get an error either saying that it’s not a string or not an image depending on what you passed to the resolver.</p><p>If you run it now you should see a new array of errors after the data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1hfvb1FRBMaQaBTOaDSoQ.png" /></figure><p>Awesome! We created our first Scalar and used it to validate Image links.</p><p>You can see the finished code here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F4qlo54l7k9%3Fview%3Dpreview&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F4qlo54l7k9%3Fview%3Dpreview&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F4qlo54l7k9%2Fscreenshot.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b424df4cda1061555c995de6b5bd2ca/href">https://medium.com/media/8b424df4cda1061555c995de6b5bd2ca/href</a></iframe><p>If you wanna see more examples I suggest looking at the source code of libraries like <a href="https://github.com/Saeris/graphql-scalars">graphql-scalars</a> and see how they handle the validation.</p><p>Photo by <a href="https://unsplash.com/photos/B3l0g6HLxr8?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Blake Connally</a> on <a href="https://unsplash.com/search/photos/computer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p>Written by Sara Vieira — Developer Advocate at <a href="https://www.yld.io/">YLD</a>.</p><h4>Interested in GraphQL? You may also like:</h4><ul><li><a href="https://medium.com/yld-engineering-blog/easier-graphql-wrappers-for-your-rest-apis-1410b0b5446d">Easier GraphQL wrappers for your REST API’s</a></li><li><a href="https://medium.com/yld-engineering-blog/the-new-apollo-server-is-3f2119e4e7c9">The new Apollo Server is 💯</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=999f009d3f46" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yld-blog/create-custom-graphql-types-999f009d3f46">Create custom GraphQL types</a> was originally published in <a href="https://medium.com/yld-blog">YLD Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easier GraphQL wrappers for your REST API’s]]></title>
            <link>https://medium.com/yld-blog/easier-graphql-wrappers-for-your-rest-apis-1410b0b5446d?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/1410b0b5446d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rest]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Mon, 17 Dec 2018 08:52:40 GMT</pubDate>
            <atom:updated>2019-03-08T19:02:56.688Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7lUGdzcGtBtv_b1TbGFEQ.jpeg" /></figure><p>A very common use case for building <a href="https://www.yld.io/speciality/graphql/">GraphQL</a> API’s is to wrap REST API’s for a better experience in the Frontend and also some more type checking in our backend.</p><p>Apollo knows this so there is a package to help with this and it’s called apollo-datasource-rest. It’s strong points is that it handles some of the caching for you as it runs through their cache and also it exposes a class that makes it easier for us to keep our code clean.</p><p>If you wanna follow along you can start with the starter ApolloServer sandbox on CodeSandbox that you can find <a href="https://codesandbox.io/s/apollo-server">here</a>.</p><h3>Wrap our REST API</h3><p>For this example I am going to use the <a href="https://randomuser.me/">RandomUser API</a> and we will create two queries. One for getting one random user and one for getting a set of users.</p><p>So let’s start by defining our Schema and it should look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5eb2bd2e6209b11c94fbd2d9b9ad2812/href">https://medium.com/media/5eb2bd2e6209b11c94fbd2d9b9ad2812/href</a></iframe><p>Some of the return values from the API I don’t really want to return so I will ignore them.</p><p>Now let’s create our class where we will use apollo-datasource-rest and in here the first thing we need to do is to extend the RESTDataSource class that the package exposes to us.</p><p>In it we have a constructor where we can define our base API url. Our file should look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9f1b99c5978ac4ab791d6b1b4ad6a4c/href">https://medium.com/media/a9f1b99c5978ac4ab791d6b1b4ad6a4c/href</a></iframe><p>Now that we have the basis of our class we need to define our functions and they will all have a signature close to this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f93e730232768d505890bbabdd82b14/href">https://medium.com/media/4f93e730232768d505890bbabdd82b14/href</a></iframe><p>So we create async functions that will fetch our data, give it any parameters that we want and from the parent RESTDataSource we have access to some methods to interact with API’s.</p><p>Besides the get method we also have the normal methods to allow for POST, PUT, PATCH, and DELETE requests so you can build any type of request to your REST api.</p><p>Let’s create our function to get one single user:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/693b646695d38d56ee66565f4f263a2b/href">https://medium.com/media/693b646695d38d56ee66565f4f263a2b/href</a></iframe><p>Now that we have this we can use it in our resolvers.</p><h3>Using our data sources</h3><p>Moving back to our index.js when we initialise our ApolloServer there is an option we can pass called dataSources and that goes after our resolvers definition.</p><p>This property takes a function that will return an object with all your dataSources so in our case our new ApolloServer instantiation will now look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c24d3157910dd57ae0c86c05020eafbe/href">https://medium.com/media/c24d3157910dd57ae0c86c05020eafbe/href</a></iframe><p>By passing it as a dataSource we now have access to it on all our resolvers as part of the third argument so in our resolver to get the user we need to call the function we created in our class like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ebfefaaeff6c5b0c61fd2b1858c831c/href">https://medium.com/media/7ebfefaaeff6c5b0c61fd2b1858c831c/href</a></iframe><p>If you now try to run the getUser query like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f206a665e2a9d46a26bc1a8c88bc875c/href">https://medium.com/media/f206a665e2a9d46a26bc1a8c88bc875c/href</a></iframe><p>You should already see some data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lLvmxcuw1S-jhE27ZuVgvg.png" /><figcaption>Return one user</figcaption></figure><p>Let’s now code our getUsers function and in this one let’s also allow the user pass the number of users they wants to receive.</p><p>The endpoint for that is: <em>https://randomuser.me/api/?results=number </em>so let’s code our function with some sensible defaults:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb1399e706a6c166483a8502af760375/href">https://medium.com/media/cb1399e706a6c166483a8502af760375/href</a></iframe><p>So here we get a variable called people and assign it a default of 10 so if the user doesn’t pass a the argument we will just send 10 random people. This feature is called Default Parameters and you can read all about it at <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters">MDN</a>.</p><p>Let’s now add a new function to our resolvers for query:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/525ab0a34ecc4e00c3089aa5c378f516/href">https://medium.com/media/525ab0a34ecc4e00c3089aa5c378f516/href</a></iframe><p>In here we use the second parameter of the function and that’s because we get whatever the user passed as a parameter to the query.</p><p>If you now run something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b10e333d6aaefef925bc149194357a6/href">https://medium.com/media/4b10e333d6aaefef925bc149194357a6/href</a></iframe><p>You should get three random users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TJJCC1ZJNS4933vBQNpaCQ.png" /><figcaption>Getting a certain amount if random users from the API</figcaption></figure><h3>Wrapping up</h3><p>In my opinion this is a more elegant way of wrapping our REST API’s as we have a clear definition of what we are doing in each function and also we get Apollo to take care of all that’s not the actual fetching and modelling of our data.</p><p>If you want the see the full coded example you can see it here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fxvw475x3ww&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fxvw475x3ww&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fxvw475x3ww%2Fscreenshot.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/be6cb65ac894bcd7e3b2f9e69be7a7b2/href">https://medium.com/media/be6cb65ac894bcd7e3b2f9e69be7a7b2/href</a></iframe><p>Photo by <a href="https://unsplash.com/photos/vdWewqfr_V0?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Fancycrave</a> on <a href="https://unsplash.com/search/photos/computer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p>Written by <a href="https://twitter.com/NikkitaFTW">Sara Vieira</a> — Developer Advocate at<a href="https://www.yld.io/"> YLD.</a></p><h4>Interested in GraphQL? Read more about it:</h4><ul><li><a href="https://medium.com/yld-engineering-blog/create-custom-graphql-types-999f009d3f46">Create custom GraphQL types</a></li><li><a href="https://medium.com/yld-engineering-blog/the-new-apollo-server-is-3f2119e4e7c9">The new Apollo Server is 💯</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1410b0b5446d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yld-blog/easier-graphql-wrappers-for-your-rest-apis-1410b0b5446d">Easier GraphQL wrappers for your REST API’s</a> was originally published in <a href="https://medium.com/yld-blog">YLD Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The dark side of conferences]]></title>
            <link>https://uxdesign.cc/the-dark-side-of-conferences-4b103143179f?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b103143179f</guid>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 13:46:18 GMT</pubDate>
            <atom:updated>2018-09-27T01:05:58.031Z</atom:updated>
            <content:encoded><![CDATA[<h4>Like the click baity title? Nice! Now let’s talk about the “glamorous” conference life.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jrVerkXagGLFGiuioaWipA.jpeg" /><figcaption>This photo was taken at React Native EU. No hate on them, they were amazing to me I just fucking love this photo.</figcaption></figure><p>I grew up mostly average class, I was never not eating poor or anything but I never had big stuff mostly because my parents couldn’t afford it. I never even flew until 2014 and that was for my first conference so most of the my vacations were camping and stuff like that and I always saw conferences as the real vacations where I could actually travel places. Up until last year before joining YLD I made 16K a year soooooo … not a lot of travelling was possible.</p><p>I’m not saying this for you to feel sorry for me, don’t do that, I had a fucking awesome childhood and I still love camping. I am saying this for the rest of the article to make sense.</p><p>For as long as I can remember my mom makes minimum wage and that is 580 euros in Portugal so I have been pretty aware of how lucky I am to be able to make waaay more then she does sitting at a computer, doing what I love and getting shipped to free trips. I was also always brought up to accept things when they are free because I couldn’t afford them if they weren’t.</p><p>In the beginning that’s what you see. You see free places to go where you can share your nerd passion with other people that are just excited as you. You can make friends like you and not feel bad about talking JavaScript stuff during lunch and it’s fucking amazing because you feel like you belong and that is like a drug.</p><p>Also someone literally emails you and tells they like the way your present and want to fly you and pay for a trip in exchange for you talking about something you love … Who the fuck would say no to that?!</p><p><strong>Me apparently!</strong></p><h3>What happened?</h3><p>I find it funny that a lot of people envy me but most of the people who don’t are people who travel for work too. Traveling is amazing … Until it’s work.</p><p>I find it really hard to say no to things, due probably to my low self esteem I insist on saying yes to things when asked and so I got myself in about 50 conferences and meetups this year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vjep8NakRbcAkWAjg_8GwA.png" /><figcaption>You thought I was kidding?! — The app is <a href="https://www.notion.so/">https://www.notion.so/</a></figcaption></figure><p>Some people can look at this and say this isn’t healthy and some people just see how lucky I am to be invited to these things and don’t take me wrong I am very lucky but doing this takes a huge toll in you as a human.</p><p>The person who got really excited to get on a plane and travel somewhere new now forgets she has flights and wants to be home for weeks in a row.</p><p>If you travel this much you don’t really have a home, your home is everywhere and no matter of how much of a digital nomad you consider yourself to be you need a home, you need somewhere where everything is okay and you just feel like you are home.</p><p>I didn’t have that for so long, I am trying to make berlin my home but I honestly don’t even know how to do that. I am so used to living out of hotel rooms and airbnbs that I honestly don’t know how to make somewhere feel like home anymore. This feeling struck me really hard, I felt homeless, I felt alone.</p><p>A lot helped to this feeling, one of the things is that I mostly travelled alone and that sometimes is a good idea but not always, there are talks or days where you need a friend to cheer you up and no one is there.</p><p>That’s the thing about travelling. It’s all fun because that’s what you show but no one is there when you crying in a hotel room because you feel so alone. No one is there when you feel so overwhelmed by all the things you need to do that you literally want to cancel everything. Most people care about the good part not about this part, they don’t understand this part. Most people don’t understand how something so “good” can break someone inside.</p><p>I don’t blame them, it’s hard to understand how someone can LITERALLY complain about getting free shit!</p><p>Nothing is free though, everything has a price. Every time I do a talk I am shit scared that someone will ask a question that will unmask me as a fraud or whatever because imposter syndrome is a bitch. Every time I get on a stage I still get nervous and shake everywhere. Doing this over and over has a price on your brain, on your health and on you in general.</p><p>Not just this but also many times the fact that when you go somewhere like this you are expected to be out of your comfort zone, you are supposed to socialize with people 24/7 and that’s not me. I feed on alone times, that’s how I get my energy and being somewhere all day where I have to interact with people drains me inside mainly when it’s somewhere you don’t know. You can’t go home. Even if you want to badly you can’t just disappear and go home because that’s not how the world works no matter how much you want it work like that sometimes.</p><p>It’s funny because when I was starting I always looked at conference people like the awesome ones, those who had their life figured out and I always assumed that if I could do that, I would feel awesome and I would feel like I had my life figured out. I learned the hard way that having people clap for you doesn’t actually make you feel better about yourself when you are alone.</p><h3>Are you cancelling every conference?</h3><p>No. I cancelled some and will be more careful about the ones I do in the future, I will take my health and happiness more into consideration. That doesn’t mean I’ll stop that just means I won’t drain myself to the point of having to write one of these again. I still love conferences but like everything in life it needs to be in moderation.</p><p>I hope this makes sense to someone and I hope the next time someone travels a lot for work you don’t just look at them and think how lucky they are.</p><p>I hope next time you ask them how they feel. Sometimes just hearing someone ask that helps more then you can ever imagine.</p><p>—</p><p>If you made this far here is a meme:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mOzkpg74CdNFSS7ladf8VA.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff%2F50d69a%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2F50d69a%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/05d5fd32eda31cbd1b83287606744532/href">https://medium.com/media/05d5fd32eda31cbd1b83287606744532/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b103143179f" width="1" height="1" alt=""><hr><p><a href="https://uxdesign.cc/the-dark-side-of-conferences-4b103143179f">The dark side of conferences</a> was originally published in <a href="https://uxdesign.cc/">UX Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy your Create React App with Docker and Nginx]]></title>
            <link>https://medium.com/yld-blog/deploy-your-create-react-app-with-docker-and-ngnix-653e94ffb537?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/653e94ffb537</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Mon, 06 Aug 2018 10:00:36 GMT</pubDate>
            <atom:updated>2019-03-08T19:59:00.071Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3VSP68hP2R8NyDJS5J47A.jpeg" /></figure><blockquote>First thank you to <a href="https://medium.com/u/6379929b352">Simona Cotin</a> and <a href="https://medium.com/u/22fa2f6fc2af">Super Diana</a> for answering the noob docker and nginx questions and reminding me that nginx is better for static files than node. Also thank you to the amazing humans who built a<a href="https://github.com/Microsoft/vscode-docker"> Docker extension</a> for VSCode.</blockquote><p>One of my main frustrations when it comes to Create <a href="https://www.yld.io/speciality/react-js/">React</a> App, or really any frontend app that is served statically without a server backing it, is that your routes are now gone. You can access them from inside the app and go from page to page but if you try to access a page directly well… This happens: <a href="https://isthereuber.in/leiria">https://isthereuber.in/leiria</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pTsGs32F5JQXfAN4JoBWOA.png" /></figure><p>This is not okay, I know the website is static but the user doesn’t need to know.</p><h3>Nginx to the Rescue</h3><p>We will now need to create a nginx configuration for our server. The reason I choose nginx over node is mostly because it has been proven to be faster for static assets but you can totally do this with node.</p><p>A configuration file for nginx is a nginx<em>.conf </em>file so let’s start by creating that file and start coding it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2cd8e08343029ccfd6da063c7a64b92/href">https://medium.com/media/a2cd8e08343029ccfd6da063c7a64b92/href</a></iframe><p>This is a pretty standard configuration for nginx and we tell it where to show our files and what the cache expiration date is. There is also some helpers for 404 and logs.</p><p>We don’t enable gzip here but for an example with it you can look <a href="https://github.com/SaraVieira/rick-morty-random-episode/blob/master/nginx.conf">here</a>.</p><h3>Docker time</h3><p>Now that we have our nginx config we can now create our <a href="https://medium.com/yld-engineering-blog/when-should-i-use-docker-77ae2736a487"><em>Dockerfile</em></a> and we will start by stating what is the base image we will be using:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9568db0071cbf699146dd7454b0e2913/href">https://medium.com/media/9568db0071cbf699146dd7454b0e2913/href</a></iframe><p>After this we need to tell docker what it needs to run our app and in this case we need to do three things:</p><ul><li>Copy the <em>build </em>folder over to<em> /var/www</em></li><li>Copy the nginx<em>.conf</em> to it’s folder in <em>/etc/</em>nginx<em>/</em></li><li>Expose the port 80 to the public since that is the one we are using in the nginx config</li></ul><p>Details on how to do this are below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04a021bf3020f159aa581ed2a5b5f60b/href">https://medium.com/media/04a021bf3020f159aa581ed2a5b5f60b/href</a></iframe><p>Now to finish our <em>Dockerfile</em> we need to tell it what command to run and for that we will the nginx cli and pass it as the entrypoint in our <em>Dockerfile</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2af60033232f7ad28f21762ac5b231a/href">https://medium.com/media/f2af60033232f7ad28f21762ac5b231a/href</a></iframe><p>As you can see we run nginx with <em>-g daemon off;</em> so that nginx stays in the foreground so that Docker can track the process properly (otherwise your container will stop immediately after starting). You can read more about this <a href="https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/">here</a>.</p><p>You can now build and tag this image with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dff2b55ca6e3d1f6a400ac9577fa2dc/href">https://medium.com/media/6dff2b55ca6e3d1f6a400ac9577fa2dc/href</a></iframe><p>And then run it with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd5b5cf390ed9d561b024a37c003431e/href">https://medium.com/media/fd5b5cf390ed9d561b024a37c003431e/href</a></iframe><p>If you use <a href="https://now.sh/">now</a> you can just deploy this as it is and now will build and run the image on their own servers.</p><p>We now have static routes on our static projects! If someone hits any route on your webapp this will be redirected to index.html and your app will work flawlessly.</p><p>This is the webapp I used to test this approach: <a href="https://github.com/SaraVieira/rick-morty-random-episode">https://github.com/SaraVieira/rick-morty-random-episode</a></p><p><a href="https://rick-morty-random-episode.now.sh/">https://rick-morty-random-episode.now.sh/</a></p><p>Routes 🎉</p><p>Photo by <a href="https://unsplash.com/photos/aTt_rNa3gmM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Marten Bjork</a> on <a href="https://unsplash.com/search/photos/javascript?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p>Written by <a href="https://twitter.com/NikkitaFTW">Sara Vieira</a> — Developer Advocate at <a href="https://www.yld.io/">YLD</a>.</p><h4>Interested in React? Read more about it:</h4><ul><li><a href="https://medium.com/yld-engineering-blog/rolling-your-own-redux-with-react-hooks-and-context-bbeea18b1253">Rolling your own Redux with React Hooks and Context</a></li><li><a href="https://medium.com/yld-engineering-blog/create-custom-graphql-types-999f009d3f46">Create custom GraphQL types</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=653e94ffb537" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yld-blog/deploy-your-create-react-app-with-docker-and-ngnix-653e94ffb537">Deploy your Create React App with Docker and Nginx</a> was originally published in <a href="https://medium.com/yld-blog">YLD Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Re: Mental Health]]></title>
            <link>https://medium.com/@nikkitaftw/re-mental-health-62e071f87e4?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/62e071f87e4</guid>
            <category><![CDATA[mental-health]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Fri, 27 Jul 2018 20:11:31 GMT</pubDate>
            <atom:updated>2018-07-27T20:11:31.248Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ExFh2ni-DnNjVRAccxjHYg.jpeg" /></figure><p>A couple of months ago I spoke about something in my brain that haunted me for years, I did a talk about mental health and panic disorders at Agent Conf and if you relate to this in any way here is the video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FbovBQtB_PDo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbovBQtB_PDo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FbovBQtB_PDo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c900f4317f413eb86033028b4a76e3c8/href">https://medium.com/media/c900f4317f413eb86033028b4a76e3c8/href</a></iframe><p>I can never thank the agent conf team enough for letting me do this talk, allowing me to talk about these subjects in a tech conference and supporting me each step of the way.</p><p>After this talk I have been invited to speak at three more conferences about this topic and it’s the talk I would travel the most to deliver and raise awareness. However, this particular talk is not what I am here to discuss but the feedback I got about it to the present day and how I am doing coping now.</p><p>This feedback stuck with me:</p><blockquote><em>You’re normalising having a broken brain &amp; helping people realise that they can make it despite that. by </em><a href="https://twitter.com/ScribblingOn"><em>ScribblingOn</em></a></blockquote><h3>The feedback part</h3><p>This is exactly what I wanted, my talk was not supposed to cure anyone, my only objective was and still is to make people aware that they are not alone, that being broken is not something you have go through alone.</p><p>I want everyone to know that no matter your background this can happen to everyone and that you should ask for help, you shouldn’t be ashamed like was.</p><p>And I got plenty of people that DM’d me or personally thanked me because they were scared of what was going on but felt alone and didn’t know who to tell or what to do, and that I helped them get out and find help. This is the best thing I could have ever heard. Like I said in the talk I don’t care about looking stupid (point in fact: <a href="https://imgur.com/OpAiCw2">https://meme.iamsaravieira.com</a>) as long as it helps one person feel less alone. To this day I believe this talk was the best thing I did in my life.</p><p>I also got some feedback from people saying that that I pretty much explained their life in this talk, that they had problems but didn’t know what was wrong and this was the best way to make others understand. Repeating myself, this talk is the best thing I’ve ever done because it actually helped people, not in coding like most things I do but in life! It crossed the boundaries of programming languages and even professions and got people united, relating to the situation and the feeling of being alone. It made them realise they are DEFINITELY not alone and that we are all in some way suffering from something no matter how we sound and look.</p><h3>Chapter 2</h3><p>Ever since I was a kid I always hated being the spotlight. I know it’s weird since I speak at conferences and appear as someone who speaks very loudly. Firstly i will explain in this “piece” why do i hate being the center of attention, and about being loud, that can be easily explained with the fact that I have terrible hearing.</p><p>After doing this talk I had people tell me they look up to me and that, to me is the weirdest thing ever since to my own views I am still broken.</p><p>One thing I think I made across with this talk is that all is fine now because I fixed one problem I had. But never assume I’m not still broken, in different ways that don’t impact my life the way the panic attacks did before, yet still broken.</p><p>I still live with depression, I have bad days where I don’t find solace or see the point of things and the saddest thing is that sometimes I look at my own talk just to remind myself what I have accomplished or read some feedback and feel so much better.</p><p>This depression leads to me having incredibly low self esteem, I don’t believe myself to be worth of pretty much anything, in my head I got all the jobs I had up to this day out of being lucky and just going through the cracks and I am just waiting for the day someone finds out and outs me. #imposterSyndrome101</p><p>I have this belief that in reality high school never ends and the way you were treated in those years has a big impact on how you perceive the world and yourself. I was made fun in high school like many of the grown up nerds, first mainly because I stuttered a lot and was also a small little ball, as in, I was 1.38m(4.5 to the US) and was a bit large around the sides so kids picked on that.</p><p>After a while this all was fixed but at the same time the gay situation happened and I went to a catholic high school, you can imagine high school was never fun, also when I was school I failed math twice in my senior year.</p><p>This all led me into me believing I don’t deserve all I have. This also led me to think I was put into a position where everyone is smarter than me because I was beaten down in school and home for something I couldn’t do anything about and y’all went to university, y’all didn’t fail math.</p><h3>So why do you do talks and workshops ?</h3><p>Brains are weird! No! Brains are really fucking weird!</p><p>If you do talks and workshops people think you are smart! Simple as that, the more talks I do the more people think I am smart and maybe if enough people believe that I am smart I will too!</p><p>People have different approaches to depression and low self esteem, some people hide and I do the opposite because hanging out with your brain alone is not something really healthy for everyone.</p><p>I guess the point of this article is to always know it’s okay to be broken. It’s okay to talk about it and doing something about it.</p><p>It’s not my fault my self esteem is super low, and your broken brain is not your fault. Normalise this shit and we will all be better humans and be much happier with what we achieved and are to achieve in life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62e071f87e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React is just JavaScript]]></title>
            <link>https://medium.com/yld-blog/react-is-just-javascript-88600553269c?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/88600553269c</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Fri, 06 Jul 2018 10:33:35 GMT</pubDate>
            <atom:updated>2019-03-08T20:07:07.225Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8yz3hkO3ynHV2qYGARynJg.jpeg" /></figure><p>Many people starting out get overwhelmed by all the things happening in the React ecosystem. There’s this idea that what happens in <a href="https://www.yld.io/speciality/react-js/">React</a> is magic and that getting started with React is super complicated unless you use tools like <a href="https://github.com/facebook/create-react-app">create-react-app</a>.</p><p>And honestly, it’s not as widely documented that you only need 5 minutes to actually inject React into your page. Dan Abramov has been trying to raise awareness to this and he’s been doing an amazing job, so taking from his idea let’s make you believe the 5 minutes statement.</p><h3>But how do I inject React into my application?</h3><p>Well, first step is finding the files to insert, and these can be found at <a href="https://unpkg.com/#/">UNPKG</a>. This is like a giant CDN of all the awesome libraries and frameworks around the world.</p><p>If you go to the URL <a href="https://unpkg.com/react@16/">https://unpkg.com/react@16/</a> you will see all the contents React has and in there you have two folders:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWbB-EMADI86A9WJE2Xf9g.png" /></figure><p>The folder UMD(Universal Module Definition) is the one we want as this one is understood by the browser without any bundler.</p><p>You need to also go to <a href="https://unpkg.com/react@16/">https://unpkg.com/react-dom@16/</a> to get the URL of development version of React Dom as we also need this library to make our project work.</p><p>The two links are:</p><ul><li><a href="https://unpkg.com/react@16/umd/react.development.js">https://unpkg.com/react@16/umd/react.development.js</a></li><li><a href="https://unpkg.com/react-dom@16/umd/react-dom.development.js">https://unpkg.com/react-dom@16/umd/react-dom.development.js</a></li></ul><p><em>Curious about the </em><em>cjs folder?</em></p><p>The cjs folder is for use with NPM and the one used when you import react with npm and cjs means CommonJS and is also what is used is used in node for example.</p><h3>Creating our HTML file</h3><p>To start we need an initial HTML file. I use VSCode, so here, to create a simple HTML file you just need to type !and then tab and you will have a starter file to insert the two links with script tags. Mine looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc1425b1ed3445ae4160302f4b065063/href">https://medium.com/media/cc1425b1ed3445ae4160302f4b065063/href</a></iframe><p>Let’s now write some react code!</p><h3>What is JSX?</h3><p>JSX (JavaScript XML) may look confusing and magical but in reality it’s just some <a href="https://en.wikipedia.org/wiki/Syntactic_sugar">syntax sugar</a> over the React.createElement function. If we don&#39;t want any type of npm or webpack magic we can just use this function that has the same effect so let&#39;s take a look at it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6JHs3BKq9kEh1OQmMcykfg.png" /><figcaption>React Create Element Parameters</figcaption></figure><p>Knowing this, we can create a simple div that has some text inside and a class to be styled in CSS, like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3262db341d37140403b0afdaba0baacf/href">https://medium.com/media/3262db341d37140403b0afdaba0baacf/href</a></iframe><p>If you reload the page, nothing will happen. This is where <a href="https://github.com/facebook/react/tree/master/packages/react-dom">react-dom</a> comes into play because react itself can be rendered into a lot of places, like native apps for iOS and Android, TV&#39;s, PDF and really anything you set your mind to.</p><p>react-dom is the library we want in order to render it into the web and then we need the ReactDOM.render function. This function takes two arguments:</p><ul><li>The element we want to render. In this case, that’s is our wrapper function</li><li>Where we want to render it to. In this function you can render it straight into the body but I would always advise to create a new element like a main and render it there. To get this element we will use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector">document.querySelector</a> and pass it our #app.</li></ul><p>In code this would look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/803bd7a05423fcf11823ae270eeec756/href">https://medium.com/media/803bd7a05423fcf11823ae270eeec756/href</a></iframe><p>If you reload the page, you can see our wrapper but it doesn’t really look nice so let’s add some CSS to it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a269d1d6b0d3cd27c768746ea109b1f4/href">https://medium.com/media/a269d1d6b0d3cd27c768746ea109b1f4/href</a></iframe><p>And now you should see something like this when you open your index.html in your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDYrrSLTF_jv1_smWl97Hg.png" /></figure><p>So we got the basics of showing an element and now let’s get into some more interactivity by using <a href="https://reactjs.org/docs/faq-state.html">React’s Component State</a>.</p><h3>Creating some interaction</h3><p>In this part we are going to create the best App ever. We will get a dog photo from <a href="https://dog.ceo/api/breed/akita/images/random">https://dog.ceo/api/breed/akita/images/random</a>, show it on the page, and also add a button to refetch another dog photo. Trust me it&#39;s going to be great!</p><p>The first thing we need to do is to make our function be a <a href="https://reactjs.org/docs/react-component.html">React.Component</a>. The main difference for us is that these Components can hold state and the functions can&#39;t.</p><blockquote><em>The state contains data specific to this component that may change over time. The state is user-defined, and it should be a plain JavaScript object. — </em>via <a href="https://reactjs.org/docs/react-component.html#state">reactjs.org</a></blockquote><p>We should also consider that if we attach this state to a rendered element, this element will update once the state changes.</p><p>For our use case we will need am image property in our state that will have the source for our image. So our Wrapper should look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff0170bfdc24282b1de6afcf894f50c2/href">https://medium.com/media/ff0170bfdc24282b1de6afcf894f50c2/href</a></iframe><p>Wow! So this changed a lot so let’s through what is going on:</p><p>We now have a class instead of a simple function, you can read more about classes on the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes">Mozilla Developer Docs</a>. We also extend out of React.Component, which means that React.Component is our parent class and we inherit methods from it.</p><blockquote><em>The constructor method is a special method for creating and initialising an object created with a class. There can only be one special method with the name “constructor” in a class. A </em><em>SyntaxError will be thrown if the class contains more than one occurrence of a constructor method. </em>- via <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes">developer.mozilla.org</a></blockquote><p>A constructor can use the super keyword to call the constructor of the parent class.</p><p>After creating our base class we set the initial state that will be changed with this.state = { image: null }; the reason this is null in the start is because we don&#39;t have an image yet. Then in the render function we return the HTML element react will create for us.</p><p>Next step is creating the image tag that will have our awesome puppy:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/285bcefcb9af57e15209092f63ee9735/href">https://medium.com/media/285bcefcb9af57e15209092f63ee9735/href</a></iframe><p>We have seen this pattern before when creating our Wrapper component. The only thing we changed here from our Wrapper component is that we now receive an argument with all the props passed to the element. In the props object there is a parameter called source and set that as the src attribute of the image. We also don&#39;t pass any children as images don&#39;t really have any elements inside them.</p><p>Now for the button we do something similar:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc7f3c1227a1767fc683ab182ff900c4/href">https://medium.com/media/dc7f3c1227a1767fc683ab182ff900c4/href</a></iframe><p>Here we receive the a function that will be called when this button is clicked and will get another random puppy.</p><h3>Putting all of this together</h3><p>We have all the pieces and let’s now get this all working together in our Wrapper component by attaching these two elements to the Wrapper class and it&#39;s state.</p><p>To place these two elements as children of the Wrapper, we need to pass them as the arguments of the React.createElement function. Any argument after the second one will be seen as a children by React.</p><p>Our Wrapper will look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1062f7ffd8fa77cd4f26afbaec7ea514/href">https://medium.com/media/1062f7ffd8fa77cd4f26afbaec7ea514/href</a></iframe><p>Now it’s time we actually fetch the image and for that we will use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch</a> api provided by most modern browsers.</p><p>Let’s do that in a separate function and call it when the component mounts on the page:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e0f9af3e13667ddf3b29c52ee246fca/href">https://medium.com/media/4e0f9af3e13667ddf3b29c52ee246fca/href</a></iframe><p>First thing we did was create a getImage function and in that function we get the image. When we got it we called setState, which is how you change the state of a component in React. Assigning the state to a new object won&#39;t work because React won&#39;t re-render the component.</p><p>In componentDidMount we called the getImage function we just created and this will populate this.state.image. That we can pass it to the img element and show our new puppy. We also pass our getImage function to the button so that the user can request a new puppy.</p><p>The bind in the constructor is done because functions have their own scope and not the scope of the class it&#39;s a part of. When we have a function like this, the value of this is no longer the class methods like setState but it&#39;s instead the own function. The this keyword is confusing when you first hear about so you can read more about it in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this">Mozilla Developer Docs</a>.</p><p>We can do two things, we can bind it manually with this.getImage = this.getImage.bind(this) and this will change the scope to be the class. Or we can use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow functions</a> as these ones have no scope. In this case, for clarity, I decided to go with the first one.</p><p>You can see a live version of our awesome website here: <a href="http://react-no-jsx.now.sh/">https://react-no-jsx.now.sh</a></p><p>Also the code here: <a href="https://gist.github.com/SaraVieira/c99fd3ff7177b86c14209df92483f784">https://gist.github.com/SaraVieira/c99fd3ff7177b86c14209df92483f784</a></p><h3>I want some magic!</h3><p>So you want some JSX ah?</p><p>I like you! You live on the edge! I would say that to start you can go on the <a href="http://babeljs.io/repl#?babili=false&amp;browsers=&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=false&amp;code_lz=DwEwlgbgBAxgNgQwM5IHIILYFMC8AiAewDss8A-AKCigEgALLOOAqAdwICc4QLgB6cBDJA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=false&amp;fileSize=false&amp;sourceType=module&amp;lineWrap=true&amp;presets=es2015%2Creact%2Cstage-2%2Cstage-3&amp;prettier=true&amp;targets=Node-6.12&amp;version=6.26.0&amp;envVersion=http://babeljs.io/repl#?babili=false&amp;browsers=&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=false&amp;code_lz=DwEwlgbgBAxgNgQwM5IHIILYFMC8AiAewDss8A-AKCigEgALLOOAqAdwICc4QLgB6cBDJA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=false&amp;fileSize=false&amp;sourceType=module&amp;lineWrap=true&amp;presets=es2015%2Creact%2Cstage-2%2Cstage-3&amp;prettier=true&amp;targets=Node-6.12&amp;version=6.26.0&amp;envVersion=">Babel’s online playground</a> and play with it a bit. Once you understand it and want to apply to this exercise without much setup you can follow <a href="https://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project">this guide by the react team</a>.</p><p>After this you can start playing on <a href="https://codesandbox.io/s/new">codesandbox</a> that offers the whole environment online.</p><p>Adding JSX to a project is just like adding a CSS preprocessor. It’s a single command you can run to convert all your script tags. You don’t need to install webpack or similar tools.</p><h3>Conclusion</h3><p>Hope this cleared some of the magic React sometimes feels to have and got you excited about it. Even if you already know React I hope this has taught you some new fundamentals you might not be aware of.</p><p>Go and build dope stuff with React! ⚛️</p><p>Thank you to Dan Abramov for bringing this to light!</p><p><em>Thank you to </em><a href="https://medium.com/u/8072d0c818ed"><em>Carolyn Stransky</em></a><em> and </em><a href="https://medium.com/u/fdf5d10184ed"><em>Carlos Vilhena</em></a><em> for reviewing my horrible grammar !</em></p><p><em>Also Thank you to </em><a href="https://medium.com/u/b031a508ddaf"><em>Artem Sapegin</em></a><em> for the awesome photo</em></p><p>Written by <a href="https://twitter.com/NikkitaFTW">Sara Vieira</a> — Developer Advocate at <a href="https://www.yld.io/">YLD</a>.</p><h4>Interested in React? Read more about it:</h4><ul><li><a href="https://medium.com/yld-engineering-blog/rolling-your-own-redux-with-react-hooks-and-context-bbeea18b1253">Rolling your own Redux with React Hooks and Context</a></li><li><a href="https://medium.com/yld-engineering-blog/a-tale-of-react-server-side-rendering-cb95a441ca01">A tale of React Server Side Rendering</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88600553269c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yld-blog/react-is-just-javascript-88600553269c">React is just JavaScript</a> was originally published in <a href="https://medium.com/yld-blog">YLD Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The new Apollo Server is ]]></title>
            <link>https://medium.com/yld-blog/the-new-apollo-server-is-3f2119e4e7c9?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f2119e4e7c9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[apollo-server]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Tue, 26 Jun 2018 18:06:43 GMT</pubDate>
            <atom:updated>2019-03-08T20:09:50.674Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5I8Wu8EpyEKwZF8oYra3bQ.jpeg" /></figure><p>On the 15th I was at <a href="https://www.graphql-europe.org/">GraphQL Europe</a> and I want take some time to talk about the new release by the awesome apollo team that was announced there with a talk by <a href="https://medium.com/u/c827782c6410">Peggy Rayzis</a> about the new Apollo Server.</p><p>You can checkout the slides she used so you can get an idea of the new server.</p><h3>Peggy Rayzis 👩🏼‍💻 on Twitter</h3><p>Apollo Server 2.0 is officially out of beta! Learn about all the latest features and what&#39;s in store for the future in my talk from @graphqleu. 🚀 💻 Slides: https://t.co/az1ev3GLmH 🔗 Repo w/ learning resources: https://t.co/Ezx62TeGY0</p><p>In this article I’m going to focus on how to get started with it.</p><h3>How to get started</h3><p>First step is to create a folder and initialise npm in it so that we can install the apollo server dependency:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a41dfaf644d7e106e5500db1e21d10f4/href">https://medium.com/media/a41dfaf644d7e106e5500db1e21d10f4/href</a></iframe><p>All that -y does is skip all the questions and give you a shinny new project to start with. Let&#39;s now install our dependencies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27e17b81f061af99540ecf52988f5b80/href">https://medium.com/media/27e17b81f061af99540ecf52988f5b80/href</a></iframe><p>We need the apollo-server@rc to get all the new shiny features, graphql because, well, we are working with it, and I am installing <a href="https://www.npmjs.com/package/random-id">random-id</a> to give us an easy way to create random and unique IDs.</p><h3>Our Data</h3><p>In this example, I am going to use a movies array that we will query and mutate. So our index.js should look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2f852382e8f89652078af75b91a667c/href">https://medium.com/media/f2f852382e8f89652078af75b91a667c/href</a></iframe><p>If you’ve never met me you should know I love horrible movies.</p><p>In this code we are importing the server and the query language(gql) from apollo-server and then importing random-id.</p><p>As for our data we have a list of two movies that have an ID, title and a year. With this we can start defining our types.</p><h3>The Type Definitions</h3><p>So, our id will be of type ID, the title of type String and, our year of type Integer. So we can start by adding that after our movies array, and also a root query for all movies that will return an array of movies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dab6dc39f0244da9a677d975c7ff8933/href">https://medium.com/media/dab6dc39f0244da9a677d975c7ff8933/href</a></iframe><p>Awesome! We already have a small query to work with so now let’s start adding the resolvers.</p><h3>The resolvers</h3><p>This is where the magic happens. You give an argument to <a href="https://www.yld.io/speciality/graphql/">GraphQL</a> and in the resolver you tell it how to resolve that to actual data.</p><p>In our case we need to resolve the Query movies to return the array of movies we created at the top so we need something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5e76969c7dc4f334e9c3344e29def98/href">https://medium.com/media/b5e76969c7dc4f334e9c3344e29def98/href</a></iframe><p>As you can see the names need to match for graphql to know where to get the resolver from.</p><p>All done, we can now start the server 😄</p><h3>Start the server</h3><p>For this we need to create a new instance of the ApolloServer and pass it our typeDefs and resolvers. Then we need to listen for the server to start and just for convenience let&#39;s also log out the url.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/171080be39e80bc3a6803c20b894cc45/href">https://medium.com/media/171080be39e80bc3a6803c20b894cc45/href</a></iframe><p>Now by running <a href="https://www.yld.io/speciality/node-js/">node</a> index.js in your terminal you should see this in the browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TtJVe81DniJcQhIk.png" /></figure><p>Now when you run the query:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81e3d245d438298c878b638833e0385c/href">https://medium.com/media/81e3d245d438298c878b638833e0385c/href</a></iframe><p>You should get something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OFsg4rx_yY5jfjdD.png" /></figure><p>Don’t forget that your ids will be different as we are using random-id.</p><p>Awesome! We got something returned but it’s kind of bland, it would be great if we could get a movie by id right?</p><p>Let’s code that!</p><h3>Queries with parameters</h3><p>First, we need to update is our type definitions to add a new one: a query that will receive an ID as a parameter and return a single movie. So our schema will look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72685c3c9d4512cf654125991de39b66/href">https://medium.com/media/72685c3c9d4512cf654125991de39b66/href</a></iframe><p>That ! after ID means that it&#39;s a required field and that the query will return an error if not present.</p><p>With the type definitions updated, let’s now create our resolver and in there we can use the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find">find method</a> in JavaScript to get the first item that matches the id we got in the parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7073d9f3b67e9a679a81c9f2e92cb21c/href">https://medium.com/media/7073d9f3b67e9a679a81c9f2e92cb21c/href</a></iframe><p>Let’s take a look at this function and go over the parameters it receives. The first one as we can see is not used and that one is the parent but since this query is a first level query we don’t need it. In the second parameter we get all the arguments the user passed and from that I deconstruct the id so that I can use in it the find.</p><p>If you restart the server and try movie query with an ID, you will see that it returns one result.</p><p>This part is done and we can now pass parameters to our query and drill down the information we need.</p><h3>Mutations</h3><p>In this last part let’s go over creating a mutation that will add a movie to the array.</p><p>A mutation in it’s essence is the same as a query, what matters is what you do inside the resolver, the difference in name is for us to make more sense of our code.</p><p>In our type definitions we need two things. First we need to create a new Type called Mutations and this is where our addMovie Mutation will live.</p><p>Then inside this new type we create the add movie mutation that will receive two parameters, the title that is a String and the year that is an Integer and after the movie being created it will return that exact movie.</p><p>Returning what you created or deleted is a good practice in GraphQL.</p><p>In schema definition language that looks something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/529002374ab9d7aae3b79b76e7f8a8bb/href">https://medium.com/media/529002374ab9d7aae3b79b76e7f8a8bb/href</a></iframe><p>That’s all we need for our type definitions.</p><p>For our resolvers we need to think that we are really only modifying an array. That means we can push an new element to it with the two parameters the user passed and a generated id into movies and it will reflect in the array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d731dbc5fc50c976b0b42e74d028a58c/href">https://medium.com/media/d731dbc5fc50c976b0b42e74d028a58c/href</a></iframe><p>As you can see we defined a new movie with what the user gave us and a random id, we then pushed that to the movies array and finally returned what the user created.</p><p>If you restart your server server an run a mutation like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74f80e54572a13facb63f333cb9ca2d2/href">https://medium.com/media/74f80e54572a13facb63f333cb9ca2d2/href</a></iframe><p>You should get your newly created movie in the right side and when you run the movies query you will now have 3 movies instead of 2 and that means the mutation worked and you got a functional Apollo Server in about 60 lines of Javascript.</p><h3>The Code</h3><p>You can checkout all the code used here: <a href="https://glitch.com/edit/#!/apollo-serber-2-dope?path=package.json:1:0">https://glitch.com/edit/#!/apollo-server-2-dope</a> and since glitch is amazing you can even play with it here: <a href="https://apollo-server-2-dope.glitch.me/">https://apollo-server-2-dope.glitch.me/</a></p><p>Have fun with GraphQL and build amazing things ⚡️</p><p>Thank you to <a href="https://medium.com/u/7f719980dfc8">Sérgio Ramos</a> , <a href="https://medium.com/u/8072d0c818ed">Carolyn Stransky</a>, <a href="https://medium.com/u/fdf5d10184ed">Carlos Vilhena</a> and <a href="https://medium.com/u/5c70cb66e5b">Tamlyn Rhodes</a> for reviewing my blog ❤️</p><p>Written by <a href="https://twitter.com/NikkitaFTW">Sara Vieira</a> — Developer Advocate at <a href="https://www.yld.io/">YLD</a>.</p><h4>Interested in Apollo? Read more about it:</h4><ul><li><a href="https://medium.com/yld-engineering-blog/using-vue-with-apollo-65e2b1297592">Using Vue.js with Apollo</a></li><li><a href="https://medium.com/yld-engineering-blog/react-is-just-javascript-88600553269c">React is just JavaScript</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f2119e4e7c9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yld-blog/the-new-apollo-server-is-3f2119e4e7c9">The new Apollo Server is 💯</a> was originally published in <a href="https://medium.com/yld-blog">YLD Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A tale of React Server Side Rendering]]></title>
            <link>https://medium.com/yld-blog/a-tale-of-react-server-side-rendering-cb95a441ca01?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb95a441ca01</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[server-side-rendering]]></category>
            <category><![CDATA[apollo]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Mon, 04 Jun 2018 17:18:18 GMT</pubDate>
            <atom:updated>2019-03-08T20:15:05.028Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iYHm7aDJkDKNsU5T.jpg" /></figure><p>I want to start by mentioning that as of starting this I didn’t have a lot of experience with SSR besides adding styled components in a NextJS app.</p><h3>What’s the story here?</h3><p>So I have this website I created called <a href="https://awesometalks.party/">https://awesometalks.party</a> that was being rendered on the client. I was having issues with SEO and I also wanted to be cool of course and render it on the server for performance and coolness bonus.</p><p>I did this using <a href="https://github.com/jaredpalmer/razzle/">Razzle</a> that is this really awesome tool and this meant that I had a <strong>server.js</strong> that ran on the server, an <strong>app.js</strong> that was isomorphic and also a <strong>client.js</strong> for all your client needs.</p><p>Here is an example of the most basic server you can use with Razzle: <a href="https://github.com/jaredpalmer/razzle/blob/next/examples/basic/src/server.js">https://github.com/jaredpalmer/razzle/blob/next/examples/basic/src/server.js</a></p><p>Before you call me a noob, that I am, I want to say that this project was not just a <a href="https://www.yld.io/speciality/react-js/">React</a> project but it also included several things that needed to be SSR’d as well, like:</p><ul><li><a href="https://github.com/ReactTraining/react-router">React Router</a></li><li><a href="https://github.com/FortAwesome/react-fontawesome">Font Awesome</a></li><li><a href="https://github.com/nfl/react-helmet">React Helmet</a></li><li><a href="https://github.com/styled-components/styled-components">Styled Components</a></li><li><a href="https://github.com/apollographql/react-apollo">React Apollo</a></li></ul><p>So we are going to start with the ones that went super smoothly:</p><h3>React Router (AKA: At least Michael Jackson loves me)</h3><p>React Router is the best, we all know that but what I didn’t know is that server side rendering it didn’t involve a single tear and it was by far the fastest one to do so. All you need is to spread the magic over three files.</p><p>So in your app that is isomorphic you place all the routes but without the actual react-router provider like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebb04fb0c90e657de77ed2f0176ca5b0/href">https://medium.com/media/ebb04fb0c90e657de77ed2f0176ca5b0/href</a></iframe><p>In the actual client.js you place the provider since this will only run on the client but the routes are for everything:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d11869257392caaac27b813b8a90027/href">https://medium.com/media/2d11869257392caaac27b813b8a90027/href</a></iframe><p>Why isomorphic-fetch? You never know in these things!</p><p>What about the server? Well you just have to wrap your component to be SSR’d in a Static Router and that is about the only change you need to do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdda663ee8259c6fbffce030d9b3befe/href">https://medium.com/media/bdda663ee8259c6fbffce030d9b3befe/href</a></iframe><p>That’s it! Those are the only differences we have to make in the server.js to get React Router working on the server as well 😀</p><h3>Font Awesome (Yes, it needs SSR otherwise weird stuff happens)</h3><p>I actually didn’t do this one, it was a PR but I have no idea where there are docs for this, but ok.</p><p>Font Awesome was implemented in a way where only the icons we needed were imported and added to the library so that everyone doesn’t get a 3mb icon font.</p><p>There is a icons.js with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d2d67e9e209e2ae8a22cc42371f6c8e/href">https://medium.com/media/9d2d67e9e209e2ae8a22cc42371f6c8e/href</a></iframe><p>Notice the config where we tell font awesome that we will add the CSS and instead of it being added by the fontawesome package automatically. After that, this file needs to be imported into our app.js, but on this side, that is it. You just need to know that this config exists.</p><p>Then on the server some markup had to be modified for us to add the actual CSS:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5d5e75f5da1e32fc746c291dc8cee4f/href">https://medium.com/media/b5d5e75f5da1e32fc746c291dc8cee4f/href</a></iframe><p>By adding <strong><em>&lt;style&gt;${fontawesome.dom.css()}&lt;/style&gt;</em></strong> we now have perfect icons on both the client and the server and we can carry on.</p><p>Here is a <a href="https://github.com/SaraVieira/awesome-talks/pull/48">link to actual PR</a>.</p><h3>React Helmet (GOOD DOCS ARE IMPORTANT)</h3><p>Their docs are actually very good so you can see them <a href="https://github.com/nfl/react-helmet#server-usage">here</a> but what you need to change on the server is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c3dc47ff99eead961b25b2858dcf26f/href">https://medium.com/media/1c3dc47ff99eead961b25b2858dcf26f/href</a></iframe><p>There are no changes needed on the client and your SEO will be on fleek from now!</p><h3>Styled Components (css-in-js team)</h3><p>These docs are also pretty amazing so let’s start by the changes in the server. First thing we need to do is wrap our root component in their theme provider because I am also using themes with styled components, so our root components will look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b669f697dc37ac2f9d6292b2580492c/href">https://medium.com/media/6b669f697dc37ac2f9d6292b2580492c/href</a></iframe><p>After this provider component has been added to our root, we can follow the <a href="https://www.styled-components.com/docs/advanced#server-side-rendering">docs</a> that tell us to create a new server stylesheet, collect the styles of the Root and get the style tags so this means we need to add this code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dcd8969fd468014b750194ed936db41/href">https://medium.com/media/2dcd8969fd468014b750194ed936db41/href</a></iframe><p>And now add these tags into the response we send to the client:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67f63f16759f791486fae58bd0790832/href">https://medium.com/media/67f63f16759f791486fae58bd0790832/href</a></iframe><p>Now a word of warning: I also had some globally injected styles for the body and general clean up of the page and these were being ignored by the SSR.</p><p>This was happening because I was importing them in the client.js instead of the app.js and this meant it only ran in the client.</p><p>If you have any type of global styles make sure to import them in the isomorphic part of the app like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a30ce54861769de8da534f8524cdb0d/href">https://medium.com/media/4a30ce54861769de8da534f8524cdb0d/href</a></iframe><p>And you are all set for styled components and now Apollo !</p><h3>Apollo</h3><p>I love Apollo, I do, but this was a pain also because I started with Apollo Boost just to make the config easier but then hit a wall and had to download all the packages.</p><p>Let’s start by getting the place where we create the Apollo Client away from the main initial files and put it into a file that in my case looked something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a9133c667336c67e77cc0405a70742a/href">https://medium.com/media/5a9133c667336c67e77cc0405a70742a/href</a></iframe><p>And now you are thinking: What is this process.browser ? It’s just a way of figuring out if we are on the client or the server and render accordingly.</p><p>So we will initiate the ApolloClient with no devTools and in SSR Mode and then those will be switched.</p><p>And now comes this cache thing. So the way Apollo handles SSR is a little like styled components does where it gets all the things you are fetching in the page and dumps it in the dom so what this restore function does is look for the variable <strong><em>window.__APOLLO_STATE__</em></strong> and restore it as the cache for the client as well. But we haven’t gotten this to work on the server so for now nothing will happen.</p><p>On the server there is a bunch of stuff we need to do, first thing is wrap our Root in the Apollo Provider:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56e40d7303a91185585c77950bdefca2/href">https://medium.com/media/56e40d7303a91185585c77950bdefca2/href</a></iframe><p>After this we need to use <strong><em>getDataFromTree</em></strong> and what this function does is get all the queries you have in your page and fetches them all and returns a promise, after this promise is resolved we can actually get the initialState and place it in the response like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d510d57648eb694211e5d18259f312e8/href">https://medium.com/media/d510d57648eb694211e5d18259f312e8/href</a></iframe><p>And this is where Apollo gets the initial state we saw in the in the above code and like this Apollo will render everything like magic.</p><p>This is what I learned in the lengthy discovery to get the App running on SSR using <a href="https://github.com/jaredpalmer/razzle/">Razzle</a> and I hope this is useful to someone going through the same struggles into SSR and React Apps.</p><p>For anything more here is the Github repo with all the code: <a href="https://github.com/SaraVieira/awesome-talks/tree/master">https://github.com/SaraVieira/awesome-talks/tree/master</a></p><p>Also feel free to reach out to me for any questions.</p><p>Written by <a href="https://twitter.com/NikkitaFTW">Sara Vieira</a> — Developer Advocate at <a href="https://www.yld.io/">YLD</a>.</p><h4>Interested in React? Read more about it:</h4><ul><li><a href="https://medium.com/yld-engineering-blog/deploy-your-create-react-app-with-docker-and-ngnix-653e94ffb537">Deploy your Create React App with Docker and Nginx</a></li><li><a href="https://medium.com/yld-engineering-blog/rolling-your-own-redux-with-react-hooks-and-context-bbeea18b1253">Rolling your own Redux with React Hooks and Context</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb95a441ca01" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yld-blog/a-tale-of-react-server-side-rendering-cb95a441ca01">A tale of React Server Side Rendering</a> was originally published in <a href="https://medium.com/yld-blog">YLD Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Vue.js with Apollo]]></title>
            <link>https://medium.com/yld-blog/using-vue-with-apollo-65e2b1297592?source=rss-b384aa92a080------2</link>
            <guid isPermaLink="false">https://medium.com/p/65e2b1297592</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vue-apollo]]></category>
            <dc:creator><![CDATA[Sara Vieira]]></dc:creator>
            <pubDate>Sat, 31 Mar 2018 21:43:24 GMT</pubDate>
            <atom:updated>2019-03-08T20:21:02.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMzhN3iG7iQgWvu3NQfMzw.jpeg" /></figure><p>I know it may seem weird that I am writing about <a href="https://www.yld.io/speciality/vue-js/">Vue.js</a> but honestly I really like Vue, I blame Sarah Drasner and her course on frontend masters but ever since I started getting the beauty of Vue and it’s something I use sometimes, like for the original of the <a href="https://reactfest.com/">ReactFest</a> Conference website… I didn’t see the irony, I promise.</p><p>In this article we will be creating a simple list of names where we have one query for getting the names and a mutation that adds a name.</p><p>If you want to see what we are building or want to skip right to the code you can find it here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fp2mnrp56x&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fp2mnrp56x&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fp2mnrp56x%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/5acfc664540d6c54af224a566f36a52f/href">https://medium.com/media/5acfc664540d6c54af224a566f36a52f/href</a></iframe><h3>Installing ALL the things</h3><p>Thank you to Apollo Boost we just need 3 things to get started so let’s install:</p><pre>yarn add graphql apollo-boost vue-apollo</pre><p>My project also uses tachyons but that is not a necessity in any way so just these three packages are enough to do everything we want 🚀</p><h3>Setting up vue-apollo</h3><p>If you started with the <a href="https://github.com/vuejs/vue-cli">vue-cli</a> or Codesanbox you will get a main.js that starts our app, it imports vue and renders our main component and this is where we will add vue-apollo and all the config needed.</p><p>First thing is to import what we need from apollo-boost and vue-apollo:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67f53fccb0e83fe112a419a3485b624e/href">https://medium.com/media/67f53fccb0e83fe112a419a3485b624e/href</a></iframe><p>After importing this we will initialise vue-apollo by passing a uri to the ApolloClient and telling vue to use vue apollo as a plugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b71ec03389ddf469a0ef710d93e9669b/href">https://medium.com/media/b71ec03389ddf469a0ef710d93e9669b/href</a></iframe><p>Last step of our set up is to set up our provider to be the apolloProvider:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ef96451936e0cc877154816cb8d970c/href">https://medium.com/media/5ef96451936e0cc877154816cb8d970c/href</a></iframe><p>All setup is done and now we can start writing them queries.</p><h3>Files</h3><p>For this I used this file structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*XhPD2RIBKeBl7Di2xyYd1Q.png" /></figure><p>In the app.vue I just imported the Form component that will hold our mutation to add the name and the names component that will have all the names in our server.</p><p>My app.vue looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebff5d37e07630c9ccbaa0f7e990bff0/href">https://medium.com/media/ebff5d37e07630c9ccbaa0f7e990bff0/href</a></iframe><p>The queries.js file just contains all the queries we need to make requests to the server and the code is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6648f6a4789fdee8088284d30e027c06/href">https://medium.com/media/6648f6a4789fdee8088284d30e027c06/href</a></iframe><h3>Let’s get them names !</h3><p>Let’s start hacking our Names.vue and get the names.</p><p>First thing we need to do is import our query and also start our ApolloQuery component, like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db6c31ce4eafcd2f2cd8dedc09c63495/href">https://medium.com/media/db6c31ce4eafcd2f2cd8dedc09c63495/href</a></iframe><p>First thing I did was import the GET_NAMES query from our queries.js file and set it as the query property on the data so that we can call it in our template.</p><p>After that I initialised the ApolloQuery component passing it the same query we just defined and this will return a template that get the result from the query as props that we can use inside it.</p><p>Inside this template let’s first check if it’s loading or there is an error and we do that by creating two elements that check for those propreties:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e6fe09991859713bcc6282abb3739e9/href">https://medium.com/media/5e6fe09991859713bcc6282abb3739e9/href</a></iframe><p>Now that we got ourselves covered and know that when the section is rendered we have some data we can start by just displaying a list of all the names that come from our server using:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bc8a36c3dba81f7090c85c64bc2001b/href">https://medium.com/media/6bc8a36c3dba81f7090c85c64bc2001b/href</a></iframe><p>If you try this code you see that we can indeed see the names in the page but there is a small problem we haven’t defended against, what if there is data but the server has no names ?</p><p>Right now we get an empty ul but we can fix this by checking for the length of the allNameses property in data and only if it has any names we render the ul, in the case it doesn’t we will just render a span that tells the user there are no names in the server.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d725afbbd04db59bcb0399304dd2c24/href">https://medium.com/media/4d725afbbd04db59bcb0399304dd2c24/href</a></iframe><p>Awesome we got our bases covered here !</p><p>In this case we didn’t need any variables but in case we did we just need to add a prop to the ApolloQuery component called variables that accepts an object with all the variables you need.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5733eec075a547c35373d705498b1497/href">https://medium.com/media/5733eec075a547c35373d705498b1497/href</a></iframe><h3>Add them names son !</h3><p>Let’s move to our Form.vue where we will add our name to the server using a mutation.</p><p>First thing is import the mutation query from our queries.js and also create a simple form to hold the name the user inputs, your component should look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3bfed8dff414088ce7e55d38d1343e0/href">https://medium.com/media/e3bfed8dff414088ce7e55d38d1343e0/href</a></iframe><p>So far we have a pretty standard form, it just has one input that has a model for some two way data binding and also calls a method on submit.</p><p>The .prevent you see after the v-on:submit simply tells vue to prevent default before calling the method passed so that we don’t have to that manually, a great helper !</p><p>Let’s create our method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28530c9c320633cdcefac97fe2374947/href">https://medium.com/media/28530c9c320633cdcefac97fe2374947/href</a></iframe><p>All we really doing here is saving the users input in a variable called name because we want to clear the input before we actually start the mutation.</p><p>To start the actual mutation we call:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0280b3f5ede559ae0eafd44169ba98f/href">https://medium.com/media/e0280b3f5ede559ae0eafd44169ba98f/href</a></iframe><p>As you can see we call this.$apollo.mutate and we are able to do this since we instructed vue to use the apollo in our main.js. In the actual call we pass in the mutation and also all the variables we need for the mutation to occur.</p><p>If you try to add a name now and then reload the page we see that our mutation occurs and we get the new name inserted but this is not the desired outcome, we should see the the added after the mutation is done and we can do that by updating the cache in an update function that vue-apollo provides:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de6e0ba886c2b3570f21e3b8694c4a68/href">https://medium.com/media/de6e0ba886c2b3570f21e3b8694c4a68/href</a></iframe><p>In our update function we read all the names we have with our GET_NAMES query and then concat the name we just added to that array so that we can see the changes right after the mutation completes with success.</p><p><strong>What if there is an error ?</strong></p><p>We need to add a catch to our mutate function since this returns a promise. If there is an error we need to add the name the user tried to add back in the input and also populate the error key in our data object so that we can access this in the template and show the user the error:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b00eedc21d9c257b7403400125516c76/href">https://medium.com/media/b00eedc21d9c257b7403400125516c76/href</a></iframe><p>After adding this to show the error to the user we just need to add:</p><pre>&lt;div v-if=&quot;error&quot;&gt;{{error}}&lt;/div&gt;</pre><p>Somewhere in our template and if there is a mutation error the user will see the error with the name they wrote in the page, return the name to the input and also log out to the console the actual error.</p><h3>Optimistic responses</h3><p>We can stop here and the user gets a pretty good experience but in this case it does because I have a pretty fast internet and the server is also pretty fast since we are using graphcool.</p><p>However, if we had a really bad internet or the api was really slow we would have a moment where nothing happened and that may confuse the user. To fix this we can add an optimistic response, this will be something that will run and call the update function as soon as the mutation function runs instead of having it run after there is a success.</p><p>In this case we can add it at ease because it will be reverted and the catch statement will also run so adding this is a win win.</p><p>vue-apollo has a really handy optimisticResponse method in the mutate function that we can use to send a fake response and update the cache. In here we send exactly what we expect to receive from the server so we send:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86c1b88c963bbcd0d3bf779069b90858/href">https://medium.com/media/86c1b88c963bbcd0d3bf779069b90858/href</a></iframe><p>Only difference as you can see is that we send a fake id as this one will be updated as soon as the mutation completes or this will be reverted if it fails.</p><p>That’s it, we created a simple interaction with apollo and vue 🚀</p><h3>Conclusion</h3><p>I also added another mutation that deletes an item in the code sandbox that you can take a look and inspect the code even better.</p><p>Hope this was useful, I see the <a href="https://www.yld.io/speciality/react-js/">React.js</a> devs including me super excited about GraphQL and it looks like there excitement dies a bit in other frameworks but it shouldn’t as it keeps on being awesome dealing with <a href="https://www.yld.io/speciality/graphql/">GraphQL</a> in vue because of the awesome vue-apollo !</p><p>Written by <a href="https://twitter.com/NikkitaFTW">Sara Vieira</a>— Developer Advocate for <a href="https://www.yld.io/">YLD</a>.</p><h4>Interested to read more? You may also like:</h4><ul><li><a href="https://medium.com/yld-engineering-blog/the-new-apollo-server-is-3f2119e4e7c9">The new Apollo Server is 💯</a></li><li><a href="https://medium.com/yld-engineering-blog/a-tale-of-react-server-side-rendering-cb95a441ca01">A tale of React Server Side Rendering</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65e2b1297592" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yld-blog/using-vue-with-apollo-65e2b1297592">Using Vue.js with Apollo</a> was originally published in <a href="https://medium.com/yld-blog">YLD Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>