What Is GraphQL And Why Is It Used?
Tags: graphql, api, querylanguage
Published: 2020-12-02 08:38:57

There’s been a huge buzz about GraphQL and that has some of us wondering why. I remember when I first heard of it; I was suddenly reminded of graphs which I disliked back in school. It wasn’t until I had to use it for a project I was working on that I decided to check it out. If you’re now wearing those shoes or you’re just being curious about what the hype is all about, allow me to break it down for you.
##__What Is GraphQL?__

On the official [website](https://graphql.org/), GraphQL is defined as a query language for APIs and a runtime for fulfilling those queries with your existing data. It also mentioned that this query language provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

##__Why Is It Being Used?__
###__It Is A Query Language__

First, let’s talk about it being a query language. You know how there are categories of computer languages in software development such as markup languages(e.g HTML) and programming languages(e.g JavaScript), we also have query languages. And just as we can use HTML with any programming language for the web, we can also use GraphQL with any programming language.

###__You Request For Exactly What You Need__

You can think of GraphQL as a way to have a single endpoint( a url for a server or service) from which you can request for whatever you need from your database. Let’s use Facebook as a case study(since GraphQL was developed by Facebook): think about the multiple endpoints that would be required, if GraphQL wasn’t used, for just one Facebook user—one endpoint each for the user, friends of that user, friend requests, posts, comments, pages and so on. And usually, requests through these endpoints often return responses comprising resources or fields that aren’t needed. You send a request to the server for friend requests and you get all the details of each friend-to-be when all you need are their names and probably the mutual friends between them. With GraphQL, you have a single endpoint where you can request for any one or all of the requests above. 

###__It’s Easier To Evolve APIs Over Time__

Another major reason it’s being used is because with GraphQL, you can seamlessly add new fields to your API whenever you want without impacting your endpoint. Maybe it’s been a while since you built your application and it has grown so much that it needs some new features, you can simply include the fields needed for that feature in your GraphQL API on the backend and then your client can request for those fields. It really is as awesome as it sounds.

##__Your Turn__

You can learn more about GraphQL on their [website](https://graphql.org/) or go through their [practice tutorials](https://www.howtographql.com/), if you want to try your hands at it. There are also courses on GraphQL on a number of online learning platforms, including the free course on [edx](https://www.edx.org/course/exploring-graphql-a-query-language-for-apis). 
If you have experimented with GraphQL, let me know about your experiences, and if you haven’t, I’ll be looking forward to reading your stories when you eventually do.

Till next time.....