Table of Contents
GraphQL is developed by Facebook for their Internal use in 2012. And it was open-sourced and released publicly in 2015.
It is a query language for reading and mutating data in the API. The main goal behind QraphQL is to make a query that we send for fetching data smarter. So that we have been designing the endpoints and APIs easily.
The main problem is over fetching or under fetching data i.e. sometimes the data is so little that you have to make another query or the data is so large but you use only a particular part of the data only.
This is not considered a problem when you are building a project yourself but this a very big problem in terms of application speed and customer experience when you are building scalable applications which will have millions of users using them. As a result, when millions of users are requesting data in a second it will lead to an increase in the cost of the server.
In GraphQL the data in your application is represented as a graph of nodes and edges. This is also represented in the GraphQL logo. The objects are represented by the nodes and the relationship between these objects is represented by edges.
In an earlier tutorial, we have learned about the difference between REST API and SOAP. In this tutorial, we are going to see how GraphQL is different from REST API.
In REST API what happens is you are served with the Information that you are not looking for. They don’t have proper endpoints
Let’s take an example:
You want to know a Players’s height from an application. But what happens here is the API fetches the other information about the player like Name, Address, track record, etc. So as a result it takes time and you are served with extra information that you don’t need.
Let’s imagine if you are fetching 100 API queries you get 1000’s of data but you need only that 100 specific data. But this will be highly expensive. So what GraphQL does is you can get selective information from the API endpoints.
API is Like a Self-Serving Restaurant. You go to the places and you can get some extra food also.
GraphQL is like a Restaurant where you are served by a Waiter. You make smart decisions and you get what you want.
GraphQL is like a smart REST API. They are organized into types and not endpoints.
Hope this clears when to use GraphQL over REST API.
Apollo platform is in which GraphQL is predominantly implemented. It is one of the nice ways to use GraphQL in your application. It helps us to easily combine APIs, databases, and microservices in one place as a result provides developers a good experience to build applications in a Modern workspace faster. If you want to know more about Apollo please check out the Apollo GraphQL website. This platform is not associated with Facebook but makes GraphQL implementation easier and faster and is used by companies like Expedia Group, Surveymonkey, and Audi.
Yes, Because, it’s been used by top tech giants like GitHub.
GraphQL is used by companies like Airbnb, Facebook, Shopify, GitHub, Coursera, Pinterest, and Spotify, etc.
You can visit GraphQL official website to know more.
This is all about the difference between GraphQL and REST, GraphQL features, and advantages. If you have anything to discuss or ask, write in the comment. Thanks.