What is GraphQL
Query language for APIs
GraphQL is a query language and runtime for APIs that allows clients to request only the data they need.
Core Concepts
- Schema — description of data types and operations
- Queries — reading data
- Mutations — modifying data
- Subscriptions — real-time updates
Advantages over REST
- Flexibility — client defines response structure
- Single endpoint — instead of multiple REST endpoints
- No over-fetching — receive only requested fields
- Type safety — strict schema with validation
Example Query
query {
user(id: "1") {
name
email
posts {
title
}
}
}
When to Use
Ideal for applications with different clients (web, mobile), complex data relationships, and performance requirements.