Here I am not going to talk what is and how do GraphQL. I think, there are hundreds of articles about it. I want to share, what I understand in my learning and working time. if I am wrong please amend me.
When Facebook building its mobile application in 2012 its faced some issues in their REST API which led them to create GraphQL. We are also facing those problems when we design the REST API. That is :
- Poor performance
- A lot of endpoints
- Over-fetching or under-fetching of data
- Difficulty understanding APIs
- Difficulty API versioning
With GraphQL, we get a lot of new features that give you superpowers when you are building your APIs.
Minimize data fetching
Over-fetching or Under-fetching is a performance issue in REST API. Basic REST APIs always return a fixed structure of data. we should fetch the data that we need. Using GraphQL we can minimize data fetching and improve the performance of our REST API especially in case of slow network connection.
There’s also a problem with under-fetching of information. To fetch relational data we need too many requests in the server or large object with unnecessary data. This damage not only our application performance but also catch space. In that case, GraphQL can help to solve the problem.
Minimize Application endpoint
To fetch REST API data all of us use CRUD system. For each particular resource, there are GET, POST, PUT, DELETE, OPTION request methods to control data. So, in a real-world application, we would end up having a lot of endpoints for a lot of resources. It is hard to remember or control those endpoints. If you are dealing with large scale application like facebook or twitter, it is very difficult to maintaining those endpoints.
This biggest problem can solve using GraphQL. GraphQL has only one endpoint and just makes the whole server a single custom endpoint that can reply to all data questions. You just need type or mutation to control your resource.
Optimize API Versioning
One of the biggest problem in general REST API is version controlling. In different reason and adding new features, we need to change backend API several times. To keep unbreakable front-end and API users we need vertioning in our REST API.
In GraphQL there’s no need for it since you are fetching your APIs by adding new types or removing old ones. Since are fetching, how much data we need, it will be unbreakable in most of the case.
Also, there is an only one endpoint we do not need endpoint like
GraphQL might seem complex at first because it’s a technology that reaches across many areas of modern development. But if you take the time to understand the underlying concepts, I think you’ll find out that a lot of it just makes sense.
Agree? Disagree? Questions? Just let me know here in the comments. And if you’ve enjoyed this article, please consider and sharing it! Want to reach me just follow on twitter
Top comments (0)