Why GraphQL may be the next big thing ?

Rajat Sharma
3 min readDec 8, 2019

--

As a recent trend in tech industry, GraphQL may be the next big thing. I have recently learnt GraphQL through online sources, and I can say from my short experience, it has saved me a lot of time. So maybe after reading this article, it might suit your requirements as well.(This article will only explain benefits of GraphQL over current methodologies. Article doesn’t provide any how-to-do stuff with GraphQL).

Quickly I will tell you a little about GraphQL and then we will jump on our example. GraphQL is a query language (that’s what the “QL” stands for) for APIs and a runtime for fulfilling those queries with your existing data. In Layman’s term it is used to get data from the server to client and does it very efficiently as compared to the traditional methodologies.

I will take an example of Club-Members data. A Club might have multiple members and a member might be associated with multiple clubs.Say you want to get all the users(and their info) of a Club with an id of “123”.

Now with traditional REST Apis, there would be an api exposed to get particular Club with an id.

api.get(“/club/:id”)

Now to fetch a particular Member, there is an api exposed

api.get(“/member/:id”)

Now to fetch all the members associated with a particular Club, either you will call the club api and then from the members list this api provided, you will call the members api for each member. Or you will expose a third api which will be similar to get particular club with an id, but in response it will also populate each members data.

On the other hand, if you want details of all the clubs a member is part of, you will expose a fourth api. You see the problem, we either do multiple round trips, or expose different apis to fetch the details we need and this list will keep on growing as the use cases increase.

Now here comes GraphQL to the rescue. We just expose 1 api with GraphQL and then while calling that api, we let them know what data we are expecting. If we just need simple Club data we will say,

Club(id=”123”) {
// Fields we want from Club
name,
location,
memberIds -> Just the member ids, not the complete member data
}

And in case we want to fetch complete members info as well, we will just add

Club(id=”123”) {
// Fields we want
name,
location,
member {
// member specific fields we want
name,
age
}
}

Look how easy it is to fetch different kinds of data in single Api.

Conclusion :

We haven’t covered any how-to-do stuff in this article but hopefully it might have helped you get initial understanding of GraphQL. Also, GraphQL is very easy to integrate with current systems, even if you already have REST apis in your codebase. Happy Coding !!

--

--