<?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 Waruna Samarasinghe on Medium]]></title>
        <description><![CDATA[Stories by Waruna Samarasinghe on Medium]]></description>
        <link>https://medium.com/@waruna.samar?source=rss-20f874520fd5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*-dMQUwyzehvdQ_sxGlVsPw.jpeg</url>
            <title>Stories by Waruna Samarasinghe on Medium</title>
            <link>https://medium.com/@waruna.samar?source=rss-20f874520fd5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:24:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@waruna.samar/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[REST be at rest : Call me GraphQL]]></title>
            <link>https://medium.com/@waruna.samar/rest-be-at-rest-call-me-graphql-63bf6639b19b?source=rss-20f874520fd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/63bf6639b19b</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[graph-database]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Waruna Samarasinghe]]></dc:creator>
            <pubDate>Fri, 01 May 2020 16:37:22 GMT</pubDate>
            <atom:updated>2020-05-02T09:34:03.822Z</atom:updated>
            <content:encoded><![CDATA[<h3>REST be at rest : Call me GraphQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLIQwr3ofrNROKok58Dc7g.jpeg" /></figure><p>This is the first punch of the sparring session in Graph Databases. In this article, I’m going to explain about the motivation, the what , the why and the overview of the GraphQL.</p><p>I believe, this momentum might lead developers to have a thought of GraphQL. There you go.</p><h4>GraphQL resolves these issues</h4><p>When it comes to REST, the main principal is Resource. Particular resources are recognized by URL. So developers can fetch resources by dispatching a request to that URL. In a typical REST API, If developers wanted to retrieve some data from three separate endpoints, developers had to send three separate requests to the REST API. Eventually developers might fetch up making requests to multiple endpoints.</p><p>On the other hand, One of the typical mix-ups with REST is that of over and under fetching.</p><ul><li>Over-fetching is when the client downloads more resources than what actually needed for the application.</li><li>Basically Under-fetching is when a particular endpoint doesn’t come up with enough of the needed information.</li></ul><p>When it comes to GraphQL we receive data exactly what we want nothing less nothing more. Furthermore there is a single request, a single query and a single call to get data that we want. That is the potential of GraphQL.</p><p>How to permanently stay motivated? Let’s catch up the others.</p><h4>What is GraphQL and Why?</h4><p>Simply GraphQL is a query language. Facebook is the one who decided to create graphQL. As data grows it’s getting more and more difficult to serve the data to the application. So they had to find a better way to serve data to the app.</p><p>We can specify the fields in the query then we get exactly what we want and nicely organized and ready for us to use. It abstracts all complexities of using rest api brought to the audience.</p><h4>Why they called it Graph?</h4><p>If on facebook you are A and you have a friend called B. That means B is also friends with A. So there is a two way undirected connection to traverse back and forth.</p><p>Now A added another friend called C, and B added D as a friend. We can keep adding more and more connections. All are interconnected nodes as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*J2gF0pjpGQ6IwJEM0jM08A.jpeg" /></figure><p>According to graph theory A would be a node and B,C,D and E are other nodes. This is called an undirected graph because they can traverse back and forth. The data that we want to query is represented in terms of graphs. The language to create these queries is called GraphQL.</p><h4>Setting up GraphQL project with NodeJS</h4><p>First, make sure whether you have installed node js in your pc.</p><ol><li>First you have to set up a node js project on your pc.</li><li>You have to install the following npm packages: graphql , express-graphql and nodemon, then you need to configure graphqlHTTP middleware in app.js</li></ol><pre>// App.js</pre><pre>const express = require(&#39;express&#39;);</pre><pre>const graphglHTTP = require(&#39;express-graphql&#39;);</pre><pre>const schema = require(&#39;./schema&#39;)<br></pre><pre>const app = express();</pre><pre>app.use(&#39;/graphql&#39;, graphglHTTP({</pre><pre>graphiql: true,</pre><pre>schema: schema</pre><pre>}))<br></pre><pre>app.listen(4000, () =&gt; { //localhost:4000</pre><pre>console.log(&#39;Listening for requests on my awesome port 4000&#39;);</pre><pre>})</pre><h4>Creating GraphQL schemas</h4><p>When we do a query we are sending a query that says this type of data that I want from GraphQL. Schema is essentially a map of how these data are structured. To move forward, please create another file called schema.js in your project. We can create Root Query, Types and Mutation in schema.js.</p><p>Root Query describes how these connections are made. Connections meaning for example, friends, friends of friends, mutuals friends, suggestions and so forth. This data mapping is called schema. Also GraphQL has all sorts of data types that we need.</p><p>Every GraphQL query goes through three stages. <strong>Parse, Validate </strong>and<strong> Execute</strong></p><ul><li><strong>Parse</strong> : The query parse into an abstract syntax tree (AST). It’s like ESLint in JS.</li><li><strong>Validate</strong> : AST validate the query</li><li><strong>Execute</strong> : Invokes resolvers and emit the Json format Data set</li></ul><h4>Create Types</h4><pre>// Schema.js</pre><pre>const graphql = require(&#39;graphql&#39;);</pre><pre>const {</pre><pre> GraphQLObjectType,</pre><pre> GraphQLID,</pre><pre> GraphQLString,</pre><pre> GraphQLInt,</pre><pre> GraphQLSchema,</pre><pre> GraphQLList,</pre><pre> GraphQLNonNull</pre><pre>} = graphql</pre><pre>//Create types</pre><pre>const UserType = new GraphQLObjectType({</pre><pre>name: &#39;User&#39;,</pre><pre>description: &#39;Documentation for user...&#39;,</pre><pre>fields: () =&gt; ({</pre><pre>    id: {type: GraphQLID},</pre><pre>    name: {type: GraphQLString},</pre><pre>    age: {type: GraphQLInt},</pre><pre>    profession: {type: GraphQLString},</pre><pre>  })</pre><pre>})</pre><h4>Create Root Query</h4><p>As I mentioned above Root Query describes how connections are made.</p><pre>// Schema.js</pre><pre>var _ = require(&#39;lodash&#39;);</pre><pre>//dummy data</pre><pre>var usersData = [</pre><pre>{id: &#39;1&#39;, name: &#39;Anne&#39;, age: 36, profession: &#39;Programmer&#39;},</pre><pre>{id: &#39;2&#39;, name: &#39;Tom&#39;, age: 26, profession: &#39;Baker&#39;},</pre><pre>{id: &#39;3&#39;, name: &#39;Jerry&#39;, age: 16, profession: &#39;Mechanic&#39;},</pre><pre>{id: &#39;4&#39;, name: &#39;Jack&#39;, age: 26, profession: &#39;Painter&#39;},</pre><pre>{id: &#39;5&#39;, name: &#39;Jil&#39;, age: 36, profession: &#39;Teacher&#39;} ];<br></pre><pre>//RootQuery</pre><pre>const RootQuery = new GraphQLObjectType({</pre><pre>name: &#39;RootQueryType&#39;,</pre><pre>description: &#39;Description&#39;,</pre><pre> fields: {</pre><pre>   user: {</pre><pre>     type: UserType,</pre><pre>     args: {id: {type: GraphQLString}},</pre><pre>       resolve(parent, args) {</pre><pre>        // get and return data</pre><pre>       return _.filter(usersData, {userId:parent.id})</pre><pre>         }  <br>        }<br>       }<br>});</pre><h4>Mutations</h4><p>Mutation is an object type for inserting and updating data. Simply, Mutations are like POST requests. All the mutations will happen inside the resolvers.</p><pre>// Schema.js</pre><pre>//Mutations</pre><pre>const Mutation = new GraphQLObjectType({</pre><pre>  name: &#39;Mutation&#39;,</pre><pre>  fields: {</pre><pre>    CreateUser: {</pre><pre>     type: UserType,</pre><pre>      args: {</pre><pre>        name: {type: GraphQLString},</pre><pre>        age: {type: GraphQLInt},</pre><pre>        profession: {type: GraphQLString}</pre><pre>},</pre><pre>   resolve(parent, args) {</pre><pre>     let user = {</pre><pre>         name: args.name,</pre><pre>         age: args.age,</pre><pre>         profession: args.profession</pre><pre>       };</pre><pre>        return user;</pre><pre>     }</pre><pre>    },</pre><pre>  }</pre><pre>});</pre><pre>module.exports = new GraphQLSchema({ </pre><pre>query: RootQuery,</pre><pre>mutation: Mutation<br>})</pre><h4>How to try it out?</h4><p>We can use GraphiQL: <a href="http://localhost:4000/graphiql">http://localhost:4000/graphiql</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ye0VN4JSi3N1vCWBxZAbYA.png" /></figure><h4>What is the maximal Query Depth</h4><p>There is no limit, It could go on as deep as the client wants. But the Server can be configured to set maximum query depth. This helps to handle query complexity.</p><h4>Conclusion</h4><p>So far, I’ve covered some main features of GraphQL. There is so much more we can do. GraphQL mutations, Apollo Client set up, CORS, Connecting to remote DB, in-memory cache implementation ,Subscriptions, Authentication and we need to learn more about it. You have to take the time to understand the underlying concepts.</p><p>I hope this article will give you a better understanding and overview of GraphQL.</p><p>Thanks for reading. See you in the next article 😉😉!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63bf6639b19b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux-Saga : Epic of handling Side Effects]]></title>
            <link>https://medium.com/@waruna.samar/redux-saga-epic-of-handling-side-effects-8c3d600b5ce2?source=rss-20f874520fd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c3d600b5ce2</guid>
            <category><![CDATA[react-native-side-effects]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux-saga]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Waruna Samarasinghe]]></dc:creator>
            <pubDate>Sun, 19 Jan 2020 18:57:21 GMT</pubDate>
            <atom:updated>2020-01-20T17:30:16.679Z</atom:updated>
            <content:encoded><![CDATA[<h3>Redux-Saga : Epic of handling Side Effects</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*CdY8NnLMZBj8rB2uwQ80EA.jpeg" /></figure><h4>What is Redux-Saga?</h4><p>Is it like an Epic such as Game of Thrones or The Lord of the Rings? Yes, It is an Epic but not in fantasy or science fiction. It is an epic of handling application side effects. In the context of Redux, Redux-Saga is a valorous concept of handling application side effects. It performs like a middleware which allows to handle asynchronous operation by using ES6 generators.</p><p>Does Redux-Saga conceptually come from microservices Saga pattern? Both are slightly similar concepts but Redux-saga brings-out kind of leading-edge approach to handle application side effects. Apart from this, it drives well-organized applications, manipulating Asynchronous Operations, exceptional error handling and straightforward approach to testing.</p><p>When I first saw Saga function, I got a bit confused!!! 🤔, why * there? Is it an equivalent method returning a pointer like an Objective C? No, it is a generator function. So nothing to worry 😊. Furthermore, I would like to emphasize that these functions aren’t awful. These are just simple JS functions except the asterisk.</p><h4><strong>All the Side Effects move to Saga </strong>😊 😊</h4><p>UI does not execute any Application Logic apart from dispatching actions to the store. It means Redux-Saga offers an isolation place to handle all side effects. When you migrate an Angular Application to React or other JS library this will make things easier 😊.</p><h4>What is Side Effect 🤔</h4><p>Side effect is side effect 😛. It isn’t Redux related term. It may be anything that affects something outside the radius.</p><p>eg : API request , Modifying global variables, Async operation</p><h4><strong>Role of Middleware</strong></h4><p>Redux-Saga middleware is playing a significant role when dispatching actions to the store and selecting the data from the store that the container needs. It is a combination of Watcher and Worker. Furthermore, Saga runs in application background, Watches all actions that the store dispatches and reaches a decision what to do or how to handle them.</p><h4>Exceptional Error Handling</h4><p>Most of the application’s actions fail because of the Side Effects. Each action has three states START, SUCCESS and FAILURE. Though, START is a part of Watcher, most of the errors occur in SUCCESS and FAILURE. It means we have to take care of Worker. So Redux-Saga uses try/catch block to manage the behavior of SUCCESS and FAILURE.</p><h4>Getting Started</h4><p>First Step : Install package “npm install — save redux-saga”</p><p>Redux-Saga middleware to the store</p><p>store.js</p><pre>import createSagaMiddleware from &#39;redux-saga&#39;<br>import reducers from &quot;./reducers&quot;;<br>import { <br>  createStore, <br>  applyMiddleware, <br>  combineReducers <br>} from &#39;redux&#39;<br>import { rootSaga } from &#39;../sagas/root-saga&#39;;</pre><pre>const rootReducer = combineReducers(reducers); <br>const sagaMiddleware = createSagaMiddleware();</pre><pre>// Store <br>const store = createStore( rootReducer, applyMiddleware( sagaMiddleware));</pre><pre>// Middleware <br>sagaMiddleware.run(rootSaga);</pre><pre>export default store;</pre><p>rootSaga.js</p><pre>import { all, fork } from &#39;redux-saga/effects&#39;;<br>import { watchLogin, watchFetchUser } from &#39;../sagas/loginSagas&#39;;</pre><pre>export function *rootSaga () {<br> yield all([<br>   fork(watchLogin),<br>   fork(watchFetchUser),<br> ]);<br>};</pre><p>dataSaga.js</p><pre>// Watcher<br>function *watchSaga(){<br>  yield takeEvery(&#39;fetch_details&#39;, fetchData)<br>}<br></pre><pre>// Worker<br>function *fetchData(action){<br>    try {<br>        yield put({type:&#39;fetching_data&#39;})<br>        const response = yield call(&#39;api&#39;)<br>        yield put({type:&#39;fetch_data_done&#39;,data:response.data})<br>  } catch (error) {<br>        yield put({type:&#39;fetch_data_error&#39;,error})<br>  }<br>}</pre><ul><li>** Some developers write both Watcher and Worker functions together. However the above mentioned one is <strong>well organized</strong>.</li></ul><p>eg : Watcher and Worker together</p><pre>function* fetchData(action) {<br>  while (true) {<br>   try {</pre><pre>     // <strong>Watcher</strong><br>     yield takeEvery(&#39;action_type&#39;)</pre><pre>     yield put({ type: &#39;fetching_data&#39; })<br>     const response = yield call(&#39;api&#39;)<br>     yield put({ type: &#39;fetch_data_done&#39;, data: response.data })</pre><pre>  }catch (error) {<br>    yield put({type:&#39;fetch_data_error&#39;,error})<br>  }<br> }<br>}</pre><p><strong>Most painful thing</strong> in Redux-Saga is need to learn lots of <a href="https://redux-saga.js.org/docs/api/">Effect creators</a>.</p><h4>Conclusion</h4><p>In case you missed it, I wanted to emphasize the importance of using Redux-Saga. I personally recommend you to use Redux-Saga to handle application side effects. This will help you to create an awesome and well-organized application.</p><p>I hope you liked this. Thanks for reading 😊 and appreciate your feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c3d600b5ce2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native Upgrade to 0.59.8 from legacy version]]></title>
            <link>https://medium.com/@waruna.samar/react-native-upgrade-to-0-59-8-from-legacy-version-54c8c81d1f1a?source=rss-20f874520fd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/54c8c81d1f1a</guid>
            <category><![CDATA[react-native-upgrade]]></category>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native-developers]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Waruna Samarasinghe]]></dc:creator>
            <pubDate>Tue, 31 Dec 2019 19:00:11 GMT</pubDate>
            <atom:updated>2019-12-31T19:00:11.947Z</atom:updated>
            <content:encoded><![CDATA[<p>Most people are regularly raising the question that the React Native version upgrade is still a challenge. Why I emphasize about 59.8 rather than latest (0.61.5)? Because React Native 0.59.8 is a stable point before upgrading the latest. On the other hand 0.59.8 is already resolved Android 64 bit upgrading issues. I’m confident enough to say no need to worry about pushing Play Store and AppStore. Isn’t it cool?</p><p>React Native is still getting matured. So the things might change swiftly. So the Developer has to expect breaking changes when upgrading the version.The Important thing is the Developer must keep the updated React Native application. The reason for this is that the version upgrade might be a bit difficult task after a few months.</p><p>Performance is a key feature of React Native applications. Apart from this, The app can access latest APIs and libraries by keep upgrading the App.</p><h3>What didn’t work well</h3><ul><li>“ React-native upgrade ” and “ react-native upgrade@0.59.8 ” commands are not supported in legacy versions (below 0.59.0).</li></ul><h4>Pain Points</h4><ul><li>“ React-Native upgrade — legacy ” changes iOS project’s root directory and Unlinks all libraries. It is really hard to fix when the iOS root directory has been changed.</li><li>When the developer tries to upgrade by creating a new project, It’ll be a really time consuming task.</li></ul><h3>What Worked Well</h3><p>First approach before upgrading, The developer has to upgrade the app in an isolated place with a new feature branch. <strong>Guys this is a must.</strong> And It is good to stop parallel development also.</p><p>The trouble-free way to start upgrading using,<a href="https://react-native-community.github.io/upgrade-helper/?from=0.55.4&amp;to=0.59.8"> React Native Upgrade Helper</a>.</p><ul><li>First the developer has to change package.json file according to the upgrade helper, then install npm.</li><li>Make other changes according to the differences in upgrade helper, manually.</li><li>Then delete node modules, pod files and clear npm cache.</li><li>Next, the developer has to install “npm install jetifier ” to mitigate Androidx issues.</li><li>Open project using Android Studio and Xcode, try to clean and build.</li><li>Most of the time the Gradle build of the Android application might fail because of the library linking issues. Then try to unlink and link the libraries and use “npx jetifier” to handle Androidx. Then Android build issues will be fixed.</li><li>Most of the time iOS application also shows “Library not found” issues. This will be fixed after unlink and link the particular library.</li><li>Another ios specific issue is “lexical or preprocessor issue ‘Library.h’ file not found”. Definitely there will be some duplicate entries in Build phrase and Pod file. You can remove one of them. However I recommend to keep pod file entry.</li></ul><p><strong>That’s All. </strong>Do you still think that React Native upgrade is a big challenge? I hope this will help you to understand how to achieve It<strong>.</strong></p><p>Happy coding and appreciate your feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54c8c81d1f1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>