SyntaxStudy
Sign Up
GraphQL Introduction to GraphQL
GraphQL Beginner 8 min read

Introduction to GraphQL

GraphQL is a query language for APIs and a runtime for executing queries. Unlike REST APIs where you have multiple endpoints returning fixed data structures, GraphQL has a single endpoint where clients specify exactly what data they need.

GraphQL was developed internally by Facebook in 2012 and open-sourced in 2015.

Example
# REST API: multiple endpoints, over/under-fetching
# GET /users/1
# GET /users/1/posts
# GET /users/1/followers

# GraphQL: single endpoint, get exactly what you need
# POST /graphql

query GetUserWithPosts {
  user(id: "1") {
    id
    name
    email
    posts(last: 5) {
      title
      createdAt
      likes
    }
    followersCount
  }
}