0
0
GraphQLquery~10 mins

Why GraphQL exists - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why GraphQL exists
Client requests data
Traditional REST API
Multiple endpoints, over-fetching or under-fetching
Problems: Slow, inefficient, rigid
GraphQL introduced
Single endpoint, client specifies exactly what data needed
Efficient, flexible data fetching
Better developer experience and performance
Shows how GraphQL solves problems of REST APIs by letting clients ask for exactly the data they want from a single endpoint.
Execution Sample
GraphQL
query {
  user(id: "1") {
    name
    posts {
      title
    }
  }
}
Client asks GraphQL server for user name and titles of their posts in one request.
Execution Table
StepActionRequest PartServer Response PartResult
1Receive queryuser(id: "1")Fetch user with id 1User data loaded
2Resolve fieldsnameUser's nameInclude name in response
3Resolve nested fieldsposts { title }Fetch posts for userInclude posts titles in response
4Build responseAll requested fieldsConstruct JSON with name and posts titlesSend response to client
5Client receivesResponse JSONUser name and posts titlesClient has exactly requested data
💡 All requested fields resolved and response sent; query complete
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
userDatanull{id:1}{id:1, name:"Alice"}{id:1, name:"Alice", posts:[{title:"Post1"},{title:"Post2"}]}{id:1, name:"Alice", posts:[{title:"Post1"},{title:"Post2"}]}{id:1, name:"Alice", posts:[{title:"Post1"},{title:"Post2"}]}
Key Moments - 2 Insights
Why does GraphQL use a single endpoint instead of multiple like REST?
GraphQL uses a single endpoint to let clients specify exactly what data they want in one request, avoiding multiple calls and reducing over-fetching, as shown in execution_table steps 1 and 4.
How does GraphQL avoid over-fetching or under-fetching data?
Clients specify the exact fields they need in the query (execution_sample), so the server only returns requested data (execution_table steps 2 and 3), preventing extra or missing data.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what does the server do at step 3?
AFetch user name
BFetch posts for user
CSend response to client
DReceive query
💡 Hint
Check the 'Action' and 'Request Part' columns in row 3 of execution_table
At which step does the client receive the exact data it requested?
AStep 5
BStep 2
CStep 4
DStep 3
💡 Hint
Look at the 'Result' column for when data is sent to client in execution_table
If the client requested an extra field, how would the variable_tracker change?
AuserData would lose existing fields
BuserData would remain unchanged
CuserData would include the extra field after step 3
DuserData would be null
💡 Hint
Refer to how userData grows with requested fields in variable_tracker
Concept Snapshot
GraphQL exists to solve REST API problems.
It uses a single endpoint.
Clients specify exactly what data they want.
Server returns only requested data.
This avoids over-fetching and under-fetching.
Improves efficiency and developer experience.
Full Transcript
GraphQL was created because traditional REST APIs often require multiple endpoints and can send too much or too little data. This makes apps slower and less efficient. GraphQL uses a single endpoint where clients send a query specifying exactly what data they want. The server then fetches and returns only that data. This process reduces unnecessary data transfer and improves performance. The execution steps show how the server receives the query, resolves requested fields including nested ones, builds the response, and sends it back. Variables like userData grow as fields are resolved. This approach gives clients flexibility and efficiency in data fetching.