Learning Library

← Back to Library

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
0:00So what is GraphQL? As a front end developer, you  often need to send requests to multiple services in 0:06order to fill your UI with data. For example,  you have issues of under fetching or need to 0:12send requests to multiple services in order to  collect all the data you need. You might also 0:18be under fetching where you get too much data from  a single request. So you need to filter those out 0:24in your front end application. GraphQL solves this  problem by giving you one API that you can call to 0:29collect all the data you need. GraphQL is a query  language for APIs, much like how SQL is a query 0:41language for databases. For example, the following  SQL statement where you would select a number of 0:49fields from a number of tables looks like this  in GraphQL. An operation, for example, query, 1:13which is for reading data and to find all the  fields that you want to retrieve, all in a single 1:20request. So the way GraphQL is able to do this  is by having a type system. The type system is 1:26defined in a GraphQL schema. In a schema, you will  find all the available operations such as query 1:43for reading data, mutations for adding, editing,  or deleting data or subscriptions to subscribe to 1:53updates in your data. The response for all these  operations are defined in your types. These types 2:06will have type definitions for all the fields that  are available in your schema. In order to get the 2:12data from the GraphQL API you would need to take  your statement and pass it to the GraphQL API in a 2:19document. This data is usually passed over HTTP  and returns data in JSON format. In the case 2:32where we want to connect multiple data sources,  the GraphQL API will make sure to collect the data 2:37from your underlying services. In this scenario  GraphQL could also serve as a middleware, which 2:45we also call GraphQL Federation. In this video we  talked about GraphQL. I showed you how GraphQL can 2:52help you solve problems you might be facing as  a front end developer such as over fetching or 2:56under fetching. How to write the statements in  GraphQL and how GraphQL as the GraphQL schema 3:02where all the time definitions are defined. And  finally, GraphQL can be used as a middleware to 3:08collect data from all your data sources. Thank  you. If you like this video and want to see more 3:13like it, please like and subscribe. If you have  questions, please drop them in the comments below.