GraphQL is a query language for APIs that lets clients request exactly the data they need in a single request. Developed by Facebook in 2012 and open-sourced in 2015, it solves the over-fetching and under-fetching problems of REST APIs.

How GraphQL Works

With REST, you might need 3 requests to get a user's profile, their posts, and their followers. With GraphQL, you send one query that specifies exactly the fields you want from all three resources. The server returns exactly that — nothing more, nothing less.

GraphQL uses a schema definition language (SDL) to define types. You declare your data model (types, fields, relationships) and GraphQL generates a self-documenting API. Clients can introspect the schema to discover what's available.

The ecosystem includes Apollo (client + server), Relay (Facebook's client), Hasura (auto-generated GraphQL from Postgres), and Prisma (database toolkit with GraphQL-friendly output). Most implementations run on Node.js but libraries exist for every language.

Why Developers Use GraphQL

GraphQL shines in apps with complex data requirements — dashboards, social feeds, mobile apps where bandwidth matters. GitHub, Shopify, and Stripe all offer GraphQL APIs. It's particularly valuable when multiple frontend teams need different data shapes from the same backend.

Key Concepts

  • Query — A read operation where clients specify exactly which fields they want returned
  • Mutation — A write operation for creating, updating, or deleting data
  • Schema — The type system that defines your API's data model — types, fields, and relationships
  • Resolver — Server-side functions that fetch the actual data for each field in the schema
  • Subscription — Real-time updates pushed to clients over WebSocket when data changes
  • N+1 Problem — A common GraphQL pitfall where resolvers make too many database calls — solved with DataLoader

GraphQL Query and Schema

graphql
# Schema definition
type User {
  id: ID!
  name: String!
  posts: [Post!]!
}

type Post {
  id: ID!
  title: String!
  likes: Int!
}

# Client query — get exactly what you need
query {
  user(id: "42") {
    name
    posts {
      title
      likes
    }
  }
}

Learn GraphQL — Top Videos

GraphQL Educators

Apollo GraphQL
Apollo GraphQL

@apollographql

CS

API orchestration platform for AI agents and modern applications. Connect to GraphQL and REST APIs with enterprise-prove...

25.5K Subs
453 Videos
289 Avg Views
2.42% Engagement
View Profile →

Frequently Asked Questions

Should I use GraphQL or REST?

Use REST for simple CRUD APIs with predictable data needs. Use GraphQL when you have complex, interconnected data and multiple client types (web, mobile, API consumers) that need different data shapes.

Is GraphQL a database?

No. GraphQL is a query language for your API, not your database. It sits between your clients and your data sources. Under the hood, GraphQL resolvers can fetch from databases, REST APIs, or any data source.

Does GraphQL replace REST?

Not necessarily. Many teams use both — GraphQL for client-facing APIs and REST for internal services. GraphQL adds complexity (schema management, caching) that isn't always worth it for simple APIs.

Want a structured learning path?

Plan a GraphQL Lesson →