SyntaxStudy
Sign Up
GraphQL Beginner 1 min read

What is GraphQL?

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, which exposes multiple fixed endpoints, GraphQL exposes a single endpoint and lets clients request exactly the data they need—no more, no less. GraphQL solves two classic REST problems: over-fetching (receiving unused fields) and under-fetching (needing multiple round-trips to assemble a view). A single GraphQL query can retrieve nested, related data in one request, and the response shape mirrors the query shape, making it highly predictable for frontend teams.
Example
# GraphQL query — ask only for the fields you need
query GetUser {
  user(id: "1") {
    id
    name
    email
    posts {
      title
      publishedAt
    }
  }
}

# Equivalent REST would require two calls:
# GET /users/1
# GET /users/1/posts

# GraphQL response mirrors the query shape:
# {
#   "data": {
#     "user": {
#       "id": "1",
#       "name": "Alice",
#       "email": "alice@example.com",
#       "posts": [
#         { "title": "Hello World", "publishedAt": "2024-01-15" }
#       ]
#     }
#   }
# }

# All requests go to one endpoint:
# POST https://api.example.com/graphql