GraphQL
API
Backend
Architecture
Web Development
Ask anything about this article
Hi! I've read this article.
What would you like to know?
@farhan
REST has been the standard for building APIs for over a decade. Then GraphQL emerged from Facebook and challenged everything we knew about API design. Let's cut through the hype and understand when each approach makes sense.
GET /api/users/123
GET /api/users/123/posts
GET /api/users/123/followers
Three separate HTTP requests to build a user profile page.
graphqlquery {
user(id: "123") {
name
email
posts(limit: 5) {
title
createdAt
}
followers {
count
}
}
}
One request. You get exactly the data you asked for — nothing more, nothing less.
/v1/, /v2/). GraphQL doesn't — you just add new fields. Old clients continue to work.✅ Simple CRUD applications
✅ File uploads and downloads
✅ Caching (HTTP caching works out of the box)
✅ When your team is small and the API surface is limited
✅ Microservices communication (service-to-service)
✅ Public APIs (easier to document and rate-limit)
✅ Complex, interconnected data (social networks, dashboards)
✅ Mobile applications (minimize data transfer)
✅ Multiple client types (web, mobile, TV) with different data needs
✅ Rapidly evolving frontends
✅ When over-fetching is causing performance issues
typescriptimport { ApolloServer } from '@apollo/server';
const typeDefs = `
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
content: String!
author: User!
}
type Query {
user(id: ID!): User
posts(limit: Int): [Post!]!
}
`;
const resolvers = {
Query: {
user: (_, { id }) => getUserById(id),
posts: (_, { limit }) => getPosts(limit),
},
User: {
posts: (user) => getPostsByUserId(user.id),
}
};
typescriptconst userLoader = new DataLoader(async (ids) => {
const users = await db.users.findMany({ where: { id: { in: ids } } });
return ids.map(id => users.find(u => u.id === id));
});
Don't choose based on hype. Choose based on your specific needs: