<?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 Hardik Patel on Medium]]></title>
        <description><![CDATA[Stories by Hardik Patel on Medium]]></description>
        <link>https://medium.com/@passioninfinite1795?source=rss-df59dc439861------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gOiwv5r_v4pWbIaN.</url>
            <title>Stories by Hardik Patel on Medium</title>
            <link>https://medium.com/@passioninfinite1795?source=rss-df59dc439861------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 05:39:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@passioninfinite1795/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[Getting Started with GraphQL]]></title>
            <link>https://medium.com/@passioninfinite1795/beginners-guide-to-graphql-351490b360c6?source=rss-df59dc439861------2</link>
            <guid isPermaLink="false">https://medium.com/p/351490b360c6</guid>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Hardik Patel]]></dc:creator>
            <pubDate>Tue, 03 Apr 2018 22:37:18 GMT</pubDate>
            <atom:updated>2018-04-03T22:39:34.719Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial I will be covering:<br>What is REST API?<br>What is GraphQL?<br>Why you should use GraphQL for better REST?</p><p>To begin with, REST stands for Representational State Transfer which represents architectural style to interact with the data from the database using HTTP verbs and with the predefined stateless operations.<br>Many companies build there own REST services and expose the endpoints to let users interact with there services. The concept of REST came in the year 2000 by Roy Fielding and it got popular due to its adaptive nature to interact with the data hosted on the server. In most cases, the response is in the format of JSON (JavaScript Object Notation). So we can use same REST API everywhere in application development, web applications and websites too. This helps in maintaining the integrity of the data on different types of platform.</p><p>In REST, we have some endpoints that are used to perform CRUD (Create, Read, Update and Delete) operations. For example, lets consider some endpoints that are shown below:</p><ol><li>GET <a href="https://somesite.com/users/:id">https://somesite.com/users/:id</a></li><li>GET <a href="https://somesite.com/users/:id/posts">https://somesite.com/users/:id/posts</a></li><li>GET <a href="https://somesite.com/users/:id/followers">https://somesite.com/users/:id/followers</a></li></ol><p>As show above I have written some endpoints to fetch some information. The first one fetches the basic information about the User with unique ID :id. The second one fetches the Posts of a User with unique ID :id. The third one fetches all the Followers of the User having unique ID :id . Suppose we have following responses for each endpoint.</p><pre>For GET <a href="https://somesite.com/users/:id">https://somesite.com/users/:id</a><br>{<br>  &quot;id&quot;: 1&quot;,<br>  &quot;name&quot;: &quot;John&quot;,<br>  &quot;age&quot;: 20,<br>  &quot;address&quot;: &quot;XYZ ville...&quot;<br>}</pre><pre>For GET <a href="https://somesite.com/users/:id/posts">https://somesite.com/users/:id/posts</a><br>[<br>  {<br>    &quot;id&quot;: 1,<br>    &quot;title&quot;: &quot;Hello World&quot;,<br>    &quot;content&quot;: &quot;some random post contents&quot;<br>  },<br>  {<br>    &quot;id&quot;: 2,<br>    &quot;title&quot;: &quot;Second Post&quot;,<br>    &quot;content&quot;: &quot;some random post contents&quot;<br>  }<br>]</pre><pre>For GET <a href="https://somesite.com/users/:id/followers">https://somesite.com/users/:id/followers</a><br>[<br>  {<br>    &quot;id&quot;: 1,<br>    &quot;name&quot;: &quot;Bob&quot;,<br>    &quot;user_id&quot;: 2<br>  },<br>  {<br>    &quot;id&quot;: 2,<br>    &quot;name&quot;: &quot;Robbin&quot;,<br>    &quot;user_id&quot;: 3<br>  }<br>]</pre><p>Now on the Front-End side or in application I have a profile page where I have to show only the name of the User, only last two followers name, and the latest five posts. If you look closely to the responses then you can clearly see we have some problems:</p><ol><li>For profile page you are sending three requests to fetch all the information required to display the profile page.</li><li>Also, we are not utilizing all the response entities. For example, we are displaying only name of the user. So we have age, address as useless entities in our case.</li><li>We are only displaying the latest five post of the user but the response returns all the posts.</li><li>Similarly, for the followers we only want to display only last two followers but we are getting the whole list of the followers. What if we have 1000 followers?</li></ol><p>Some people may think that its totally fine if we have additional data but if you look more closely towards performance side then these will cost more internet consumption on the client side for fetching unnecessary data from the server. So how we can overcome this issue?</p><p>In 2015, Facebook announced <a href="http://graphql.org/">GraphQL</a> for performing the queries efficiently and later on they open sourced <a href="http://graphql.org/">GraphQL</a>. GraphQL is a query language for the API and server side run time for executing the queries by using the strong type system that we define for our data. This means <strong>GraphQL is not tied with any server or database instead we need to make GraphQL backed by our data</strong>. In laymen terms, we need to create our own GraphQL server.</p><p><strong>Using GraphQL we can ask for the data that we need from the server</strong> in single query. GraphQL is simple a service which can be connected in three ways:</p><ol><li>Directly with the database.</li><li>Communicating the existing APIs.</li><li>Hybrid (communicating with APIs as well as connected with the database)</li></ol><p><strong>GraphQL exposes only one endpoint</strong> which is used to query all the data that we want from the server. For example, suppose I want to fetch the only name of all the users from the server then it can be written simply as follows:</p><pre>{<br>  allUsers {<br>    name<br>  }<br>}</pre><pre>Response will be:</pre><pre>[<br>  {<br>    &quot;name&quot;: &quot;John&quot;<br>  },<br>  {<br>    &quot;name&quot;: &quot;Bob&quot;<br>  }<br>]</pre><p>Now if I want to get age as well with the name for all the users then it can be done as follows:</p><pre>{<br>  allUsers {<br>    name<br>    age<br>  }<br>}</pre><pre>Response will be:</pre><pre>[<br>  {<br>    &quot;name&quot;: &quot;John&quot;,<br>    &quot;age&quot;: 20<br>  },<br>  {<br>    &quot;name&quot;: &quot;Bob&quot;,<br>    &quot;age&quot;: 22<br>  }<br>]</pre><p>This way we can easily perform complex queries in a simple way. This is the basic feature for explaining why we should use GraphQL. There are more concepts of GraphQL like <strong>Mutations </strong>and<strong> Subscription</strong> but it solves the biggest problem of <strong>Over/Under fetching and the N+1 request problem.</strong></p><p><em>“Think in graphs, not endpoints.” </em><a href="http://www.graphql.com/articles/4-years-of-graphql-lee-byron"><em>Lessons From 4 Years of GraphQL</em></a><em> by </em><a href="https://twitter.com/leeb"><em>Lee Byron</em></a><em>, GraphQL Co-Inventor.</em></p><p>Also, It has <strong>insightful analysis</strong> of the API so that we can get to know which endpoints users are not using so that they can deprecate if not necessary. In addition to this, GraphQL comes with the<strong> benefits of the Schema and Strong Type System</strong>. It also has<strong> real time updates using subscription</strong> to get information about important events. Last but not least, <strong>GraphQL does not depend on the type of database</strong> you are using. It can be used with SQL or No SQL databases like mongodb. <br>It is a<strong> big myth that GraphQL works only for React</strong> it supports multiple platforms and languages. This makes GraphQL far better than simple REST.</p><p>Hope! this has helped you to answer your question of getting started with the GraphQL. The following are few resources you can look to learn GraphQL:</p><p><a href="https://www.howtographql.com/">How to GraphQL - The Fullstack Tutorial for GraphQL</a></p><p>The official documentation for learning GraphQL:</p><p><a href="https://graphql.org/learn/">Introduction to GraphQL | GraphQL</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=351490b360c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>