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.
On the official website, 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.
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.
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.
You can learn more about GraphQL on their website or go through their practice tutorials, 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.
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.....