Tags: graphql, api, schema, queries, mutations, apollo
Level: intermediate
TL;DR: A strongly typed query language for APIs that provides a single endpoint for clients to request exactly the data they need, solving over-fetching and under-fetching issues.
Operates through a single HTTP endpoint, usually using the POST method.
Clients define the exact structure of the response, requesting only specific fields.
Eliminates over-fetching (getting too much data) and under-fetching (needing multiple requests).
Relies on a strongly typed Schema Definition Language (SDL) acting as a contract.
Queries are used strictly for reading data without causing side effects.
Mutations are used for writing, updating, or deleting data.
Subscriptions maintain a persistent connection via# GraphQL — Cheat Sheet
Tags: graphql, api, backend, frontend, schema, dataloader
Level: intermediate
TL;DR: A query language for APIs that solves over-fetching and under-fetching by allowing clients to request exactly the data they need from a single endpoint.
Clients specify exactly what data they need, eliminating over-fetching and under-fetching issues.
Operates through a single endpoint (typically /graphql) instead of multiple resource-specific URLs.
Uses a strongly typed schema to define capabilities and validate client queries before execution.
Core operations are Queries (read), Mutations (write/update), and Subscriptions (real-time updates via WebSockets).
Resolvers are functions responsible for fetching the actual data for a specific field in the schema.
Q: What is the main difference between REST and GraphQL?R: REST exposes multiple endpoints for resources. In GraphQL, I use a single endpoint to fetch specific, deeply nested data in one request.
Q: How do you solve the N+1 problem in GraphQL?R: I use tools like DataLoader to batch and cache database requests, turning multiple small sequential queries into a single bulk query.
Q: Where should authentication and authorization be handled?R: I place authorization logic in the business logic layer or the GraphQL context, avoiding putting it directly inside individual resolvers.
Allowing deeply nested queries without depth limits, exposing the server to denial-of-service (DoS) attacks.
Writing complex business logic directly inside resolvers instead of delegating to a separate service layer.
Ignoring the N+1 query problem, causing severe performance degradation when fetching related data models.
# Schema definition example
type User {
id: ID!
name: String!
email: String!
posts: [Post!]!
}
type Query {
getUser(id: ID!): User
}
type Mutation {
createUser(name: String!, email: String!): User
}
GraphQL
# Client query example
query {
getUser(id: "123") {
name
posts {
title
}
}
}
[ ] Setting up GraphQL Subscriptions over WebSockets for real-time features.
[ ] Advanced caching strategies with Apollo Client and GraphQL.