GraphQL: A Simple Explanation Even Kids Can Understand 🤯

Hilman Ahmad
TornadoByte
Published in
3 min readJun 13, 2023

--

Photo by Kelly Sikkema on Unsplash

Hello there 🙋🏻‍♂️, I am Hilman Ahmad, the Software Engineer at TornadoByte, and today I will talk about GraphQL, which is seriously 😡 I will explain a super simple explanation even kids can understand.

GraphQL is a query language or API (application programming interface) that was created by Facebook in 2012 and was later publicly released in 2015. It’s all about making life easier for web and app developers.

You see, when these developers want to get some specific information from a server, they usually have to send a request and then get back a big chunk of data, even if they only need a tiny piece of it. It’s like getting a whole pizza when all you want is a single slice! That is traditional REST API (representational state transfer).

Photo by Kelvin T on Unsplash

But GraphQL changes the game. It lets the developers be super specific about what they want. They can ask for exactly the data they need, like toppings for their pizza. No extra stuff, just what they crave. This means they get a lightning-fast response with only the data they actually want, saving time and making their apps run smoother.

But that’s not all! GraphQL is like a ninja that can gather data from different sources and put it all together. It’s like having a magician who can bring together information from different APIs into one awesome response. It’s like mixing up the best ingredients to create the perfect dish!

So, in a nutshell, GraphQL is a superpower for developers. It’s a language that helps them get exactly what they need, ditching the excess baggage and making their apps shine. It’s like having a personal chef who serves up only the tastiest data, leaving the developers and their users happy and satisfied.

Okay, now we’ll talk about something more technical 🛠️. In the REST API, clients make HTTP requests (GET, POST, PUT, and DELETE) to specific endpoints (URLs) on the server, and the server responds with the requested data. REST APIs typically expose a fixed set of endpoints, each representing a specific resource or collection of resources. The server determines the structure and content of the response data. In this case, the clients cannot control the response data, which may lead to under-fetching and over-fetching of data.

Photo by freestocks on Unsplash

On the other hand, with GraphQL, clients have more control over the response structure as they can specify the exact fields they need, reducing unnecessary data transfer. Let’s say they have a requirement to show a table of users viewed by name, age, email, username, etc. On the top of the page, there is also a requirement for a dropdown that shows a user list view by name only. By using GraphQL, developers do not need to create multiple APIs; they are able to request data from clients based on variables that they want to have in response. Cools right? 🤓

Conclusion

The REST API is a more traditional approach with predefined endpoints and fixed response structures, while GraphQL provides more flexibility and efficiency by allowing clients to request specific data structures with a single query. The choice between GraphQL and REST depends on the specific requirements of the project and the trade-offs desired in terms of flexibility, network efficiency, and developer experience.

See you again next time 👋🏻.

--

--