GraphQL: Solving Over- and Under-Fetching
Key Points
- GraphQL provides a single API endpoint that lets front‑end developers fetch exactly the data they need, eliminating both over‑fetching and under‑fetching problems.
- It is a query language for APIs, analogous to SQL for databases, allowing clients to specify the exact fields they want in one request.
- A GraphQL schema defines a type system with operations such as queries (read), mutations (create/update/delete), and subscriptions (real‑time updates), describing the shape of the data and available fields.
- Requests are sent to the GraphQL server over HTTP and responses are returned in JSON, with the server handling the aggregation of data from multiple underlying services.
- GraphQL can also act as middleware—often called GraphQL Federation—to unify and expose data from disparate data sources through a single, cohesive API.
Full Transcript
# GraphQL: Solving Over- and Under-Fetching **Source:** [https://www.youtube.com/watch?v=c8VWxuAtVek](https://www.youtube.com/watch?v=c8VWxuAtVek) **Duration:** 00:03:20 ## Summary - GraphQL provides a single API endpoint that lets front‑end developers fetch exactly the data they need, eliminating both over‑fetching and under‑fetching problems. - It is a query language for APIs, analogous to SQL for databases, allowing clients to specify the exact fields they want in one request. - A GraphQL schema defines a type system with operations such as queries (read), mutations (create/update/delete), and subscriptions (real‑time updates), describing the shape of the data and available fields. - Requests are sent to the GraphQL server over HTTP and responses are returned in JSON, with the server handling the aggregation of data from multiple underlying services. - GraphQL can also act as middleware—often called GraphQL Federation—to unify and expose data from disparate data sources through a single, cohesive API. ## Sections - [00:00:00](https://www.youtube.com/watch?v=c8VWxuAtVek&t=0s) **GraphQL: Unified API Query Language** - The speaker explains that GraphQL offers a single, type‑driven endpoint allowing front‑end developers to request precisely the data they need, eliminating over‑ and under‑fetching problems. ## Full Transcript
So what is GraphQL? As a front end developer, you often need to send requests to multiple services in
order to fill your UI with data. For example, you have issues of under fetching or need to
send requests to multiple services in order to collect all the data you need. You might also
be under fetching where you get too much data from a single request. So you need to filter those out
in your front end application. GraphQL solves this problem by giving you one API that you can call to
collect all the data you need. GraphQL is a query language for APIs, much like how SQL is a query
language for databases. For example, the following SQL statement where you would select a number of
fields from a number of tables looks like this in GraphQL. An operation, for example, query,
which is for reading data and to find all the fields that you want to retrieve, all in a single
request. So the way GraphQL is able to do this is by having a type system. The type system is
defined in a GraphQL schema. In a schema, you will find all the available operations such as query
for reading data, mutations for adding, editing, or deleting data or subscriptions to subscribe to
updates in your data. The response for all these operations are defined in your types. These types
will have type definitions for all the fields that are available in your schema. In order to get the
data from the GraphQL API you would need to take your statement and pass it to the GraphQL API in a
document. This data is usually passed over HTTP and returns data in JSON format. In the case
where we want to connect multiple data sources, the GraphQL API will make sure to collect the data
from your underlying services. In this scenario GraphQL could also serve as a middleware, which
we also call GraphQL Federation. In this video we talked about GraphQL. I showed you how GraphQL can
help you solve problems you might be facing as a front end developer such as over fetching or
under fetching. How to write the statements in GraphQL and how GraphQL as the GraphQL schema
where all the time definitions are defined. And finally, GraphQL can be used as a middleware to
collect data from all your data sources. Thank you. If you like this video and want to see more
like it, please like and subscribe. If you have questions, please drop them in the comments below.