In an easy to understand way, GraphQL is a syntax that describes how to request data and be used to load data from a server to the client. GraphQL consists of three features that include allowing the client to determine exactly what data they need, making it easier to aggregate data from multiple sources and it uses a type system to describe the data.
The three biggest issues with the REST, there are too many endpoints, over-fetching (downloading superfluous data) and under-fetching (means that a specific endpoint doesn’t provide enough of the required information). In fact, not only that, handle data from multiple sources is also making the REST even harder.
For example, in the following image, it has too many endpoints to request. That is a list of phones on an e-commerce page. To get all data to show, at client needing a load list of data include name, review, and quantity. But the name stored in a database, the review stored in a third-party system and the quantity stored in another database. What should we do? keep more small requests like in picture or re-define one API to get all data.
Similarly, you need to have something for lunch and you want to order a burger. Then, booking a hotel for a long trip and ordering laundry. You need to call all three places on your own to address all three needs. And you must remember all communications is almost mandatory.
But think about it, if you work like a boss, and you have a personal secretary (her name is GraphQL). Still with three needs above, then what you need to do is order. You are going to talk: “Hey you, give me a burger for lunch. Please, I want to go to Ha Long Bay tomorrow, I need to book a hotel room there and order laundry today”.
It’s very easy. You don’t need to know how to work in the background and you get the results you want.
In other words, GraphQL creates a standard language to perform these tasks.
GraphQL API is made up of 3 main parts: schema, queries, and resolvers. To keep the article simple, I will not explain it in this article. You can find out more about it on the GraphQL documentation page.
In conclusion, GraphQL is a syntax that describes how to request data and be used to load data from a server to the client with one endpoint. It keeps everything be simple for the client. In the next article, I will show you how it works and how to use it.
TECH TOWN – TECHNOLOGY CONSULTING FOR YOUR BUSINESS
📞Phone: +84 81-716-0331
📍Address: Floor 6, Vinhomes Central Park, No 208 Nguyen Huu Canh, Ward 22, Binh Thanh District , HCMC.
– Japan Representative : Floor 7, Honmachi Minami Garden City, 3-6-1 Kitakyuhoji Machi, Chuo-Ku, Osaka, 541-0057, Japan
– United States Representative office: 10802 Capital Ave, Garden Grove, CA 92843, United States
– Canada Representative office: 100 City Centre Dr. Unit 206 – Level 1, Mississauga, ON, L5B 2C9