GraphQL is a query language for APIs and a runtime for executing those queries, developed by Facebook in 2012 and open-sourced in 2015. Unlike REST APIs with multiple endpoints, GraphQL provides a single endpoint where clients specify exactly what data they need, solving over-fetching and under-fetching problems. The core principle is declarative data fetching — clients define the shape of the response, and the server returns precisely that structure. Understanding GraphQL's type system, resolvers, and operation types (queries, mutations, subscriptions) is essential for building flexible, efficient APIs that scale with evolving client needs.
What This Cheat Sheet Covers
This topic spans 16 focused tables and 113 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core Operation Types
| Operation | Example | Description |
|---|---|---|
query GetUser { user(id: "123") { name email }} | • Read-only operation that fetches data without side effects • the most common operation type. | |
mutation CreateUser { createUser(name: "Alice") { id name }} | • Modifies server data • used for create, update, or delete operations that change state. | |
subscription OnUserAdded { userAdded { id name }} | Establishes a real-time connection via WebSocket or SSE to receive updates when specific events occur on the server. |