What is GraphQL?
GraphQL started its life at Facebook as a solution to problems with REST APIs: basically, REST fetched too much data! With standard REST, you access a single resource/entity, and you can't ask for just one field, you get the whole resource. This might seem like over-engineering, but if you consider billions of people scrolling Facebook on mobile phones, potentially connected to satellite networks, this resource overheard was adding up.
What problems does GraphQL solve?
REST APIs are still ubiquitous, but the REST architecture has some issues that GraphQL solves.
Overfetching and underfetching
REST has issues with overfetching and underfetching, because the way a client gets data from a server involves REST requests hitting endpoints that return fixed data structures. GraphQL uses a strong schema definition to define the contracts between clients and endpoints.
Data requirements between frontend and backend
As soon as a change is made in a web service's frontend, the data requirements of the backend have changed. Teams can define the schema when they begin a project (in GraphQL Schema Definition Language) so the frontend and backend teams can work separately, knowing the exact data structure as defined in the schema.
Faster changes
Frontend changes don't require backend changes with GraphQL, because the data needs have already been mapped in the schema. Frontend can make changes based on customer feedback without needing backend changes.
How does GraphQL work?
A basic GraphQL request looks like this:
query {
team {
id name
}
}
"data": {
"team":[ {
"id": 1,
"name": "Avengers"
}
,
…
]
}
}
Here we are querying a server for the field called team and its subfields like id and name. GraphQL allows us to define what we're looking for and structure the response we will receive, so we don't get a bunch of fields we don't need in one (relatively) big JSON file. We also have the benefit of communicating via one endpoint, instead of launching multiple requests to multiple endpoints. How does GraphQL do this?
A GraphQL schema is the backbone of every GraphQL API. It clearly defines the operations supported by the API and lets the client define what they're looking for.
GraphQL vs REST
REST is an API architecture style that facilitates HTTP connections, while GraphQL is an API querying language. REST architectures expose data through multiple endpoints, while GraphQL exposes only one endpoint. GraphQL accepts an information query from a client via this endpoint, and delivers that information from its flexible data architecture. The important distinction here is the client is defining what they are looking for, and structuring how they want to get it back.
Conclusion
GraphQL was initially popular with React developers, but has grown in popularity in the web development space since it was open sourced by Facebook in 2015. What makes GraphQL so useful is that it specifies both sides of the equation in client/server API relationships.
Frequently Asked Questions
What is GraphQL?
GraphQL is an API query language that lets a client ask for exactly the data it needs and get back exactly that, nothing more and nothing less. It was created at Facebook as a solution to the limitations of REST APIs and was open-sourced in 2015.
How does GraphQL work?
A GraphQL API exposes a single endpoint, and clients send queries to it describing the fields they want. Those queries are processed against a GraphQL schema, which is the backbone of every GraphQL API and defines the operations and data the API supports.
What is the difference between GraphQL and REST?
REST is an API architecture style that facilitates HTTP connections, while GraphQL is an API query language. A REST API typically exposes multiple endpoints that each return a fixed data structure, whereas a GraphQL API exposes one endpoint and lets the client define exactly what data it needs and how the response is shaped.
Why does GraphQL matter for developers?
GraphQL solves the overfetching and underfetching problems of REST, where endpoints return fixed structures that include too much or too little data. By letting clients request precisely the fields they need, it makes data retrieval more efficient and flexible.
What is a GraphQL schema?
The schema is the backbone of every GraphQL API. It defines the operations the API supports and the shape of the data, so clients know exactly what they can query and how responses will be structured.
How does GraphQL speed up development?
Teams define the schema upfront, which lets the frontend and backend work independently against the same agreed contract. Because data requirements are mapped ahead of time, frontend changes often do not require backend modifications.


