GraphQL is a query language in which we send the query to the
GraphQL Server. The server executes the query at runtime for fulfilling those queries with your existing data.
Let’s me make you understand this in more easy words. I suppose that you know SQL (Structured Query Language). If we are having a user table with the information about their name, age, email, phone. Now you want to fetch the name and email of the user then you will write a query for that and you will get that information. (Select name, email form the users).
You will not get age and phone of the user because you have not asked for that information. These are a thing of the server-side (backend). If you are a frontend developer and you had made 20 pages where you need users information. You will ask the backend developer that I want user information on different pages so I need an API. Backend developer will make API will give you an endpoint.
> on 6 pages you want user’s name only
> on 10 pages you want user’s email and name
> on 4 pages you want user’s name email and phone.
So you backend developer may apply two approaches.
- He will make 3 different endpoints with different data.
- He can make a common API with all the information.
What is the problem with these two approaches?
- We are having multiple endpoints. If someday we will ned user’s name and age then we need to make another endpoint.
- We are not having multiple endpoints but we are over fetching the data, on each page we don’t want the user’s phone still we are getting the data.
graphql unity flutter