logo

What is GraphQL?

GraphQL is an alternative to REST APIs. Instead of fixed endpoints returning fixed data, you write queries asking for exactly what you need.

With REST, you might hit multiple endpoints and get extra data:

GET /users/1         → user data
GET /users/1/posts   → all posts (you only need titles)

With GraphQL, one query gets exactly what you want:

{
  user(id: 1) {
    name
    posts {
      title
    }
  }
}

The server returns only the fields you requested, nested exactly as you specified.

GraphQL advantages:

  • No over-fetching (getting data you don't need)
  • No under-fetching (making multiple requests)
  • Self-documenting - the schema defines what's available

Python has great libraries for both GraphQL clients and servers.

I introduce GraphQL concepts in my GraphQL with Python course.