Course contentsShow
← Web Development
Lesson 1519 of 2,98228. GraphQL FundamentalsFree lesson

What is GraphQL?

Understanding GraphQL as a query language for APIs and its core differences from traditional REST architectures.

What is GraphQL?

You'll learn: What GraphQL is and how it fundamentally differs from REST APIs you've been working with.

Understanding GraphQL

GraphQL is a query language for APIs and a runtime for executing those queries. Unlike REST, where you request data from fixed endpoints (like /users or /posts), GraphQL lets clients ask for exactly what they need through a single endpoint, typically /graphql.

Think of REST like ordering from a fixed menu at a restaurant—you get the full "combo meal" even if you only want the fries. GraphQL is more like a buffet where you specify exactly which items you want on your plate.

Core Differences from REST

Single Endpoint vs Multiple Endpoints: REST uses multiple URLs (/users, /users/:id, /users/:id/posts). GraphQL uses one endpoint where you send different queries.

Exact Data Fetching: With REST, you often get back more data than needed (over-fetching) or need multiple requests to assemble what you need (under-fetching). GraphQL lets you request only the fields you want in a single request.

Client-Driven Queries: REST endpoints define what data you receive. In GraphQL, the client constructs a query describing the exact shape of data needed, and the server responds with data matching that structure.

Strongly Typed Schema: While REST APIs may document their structure, GraphQL requires a formal schema that defines all types, fields, and relationships—making it self-documenting and predictable.

Why It Matters

GraphQL emerged to solve real problems with REST: reducing network requests, eliminating over-fetching, and giving front-end developers more flexibility without requiring backend changes for every new data need.

Key Takeaway: GraphQL is a query language that replaces multiple REST endpoints with a single endpoint where clients specify exactly what data they need, solving over-fetching and under-fetching problems common in REST architectures.