What is GraphQL?
Definition
A query language for your API, and a server-side runtime for executing queries. Developed by Facebook, it allows clients to request exactly the data they need and nothing more.
Explain Like I'm New
In REST, the server decides what data to give you. If you ask for a User, you get 50 fields of data even if you only wanted their name. In GraphQL, the CLIENT decides. The client sends a query saying 'Give me User 1, but ONLY give me their name'. The server returns exactly that.
Real World Example
Facebook News Feed. To render the feed in REST, the app would have to fetch the posts, then fetch the authors for each post, then fetch the likes for each post (Overfetching and Underfetching). With GraphQL, the app sends one massive, specific query, and gets all the nested data back in one trip.
Common Use Cases
- •Complex UI data requirements
- •Mobile bandwidth saving
- •Microservice aggregation
Interactive Example
Interview Questions
basic
- Who originally created the GraphQL specification?
intermediate
- What problem does GraphQL solve regarding 'Overfetching'?