GraphQL
Beginner
1 min read
GraphQL vs REST: Key Differences
Example
# ----- REST vs GraphQL comparison -----
# REST: multiple endpoints, fixed shapes
# GET /users/42 -> full user object always returned
# GET /users/42/posts -> separate request
# POST /users -> create user
# PUT /users/42 -> update user
# GraphQL: one endpoint, flexible shapes
# POST /graphql with body:
# 1. Query (read)
query {
user(id: "42") {
name # only these two fields
email
}
}
# 2. Mutation (write)
mutation CreateUser($input: CreateUserInput!) {
createUser(input: $input) {
id
name
}
}
# 3. Subscription (real-time)
subscription OnNewPost {
postCreated {
id
title
author { name }
}
}
# GraphQL never breaks old clients — just add fields, deprecate old ones:
# type User {
# name: String
# fullName: String @deprecated(reason: "Use `name`")
# }
Related Resources
GraphQL Reference
Complete tag & property list
GraphQL How-To Guides
Step-by-step practical guides
GraphQL Exercises
Practice what you've learned
More in GraphQL