Why letting clients shape data changed backend design forever
Published: 2026-02-01
URL: https://thecodinggopher.substack.com/p/graphql-the-api-most-developers-misunderstand
The real problem GraphQL was built to solve “APIs fail not because they can’t return data, but because they return it in the wrong shape.” GraphQL is often introduced as an alternative to REST, but that description undersells the motivation behind it. GraphQL wasn’t created to replace HTTP or reinvent APIs — it was created because fixed API responses don’t map well to modern user interfaces. As applications grew more interactive, a single screen often needed data scattered across many backend resources.
REST endpoints, designed around servers and databases, began to leak their abstractions into frontend code. Frontend teams were forced to adapt their UI to backend constraints instead of the other way around. GraphQL flips this relationship.
From endpoints to data graphs In a REST API, the server decides the shape of the response. If a client needs something slightly different, the solution is usually another endpoint or a parameter that changes behavior. Over time, APIs accumulate special cases. GraphQL removes endpoints from the equation entirely. Instead of navigating URLs, clients navigate relationships between data. query { user(id: 42) { name posts { title comments { body } } } } This query doesn’t describe how data is fetched.
It describes what data is needed and how it relates. The response mirrors the query exactly — a structural guarantee that REST does not provide. Note: This is why GraphQL feels intuitive to frontend developers.
The query looks like the UI’s data requirements. You can see that the response JSON is different for different “queries” sent by the client. Thinking in GraphQL GraphQL fundamentally changes how we approach API calls. Rather than managing multiple URLs to fetch different resources, you interact with a single endpoint.
The Mechanics. Instead of using standard GET requests to retrieve fixed resources, you send a POST request containing a specific query. This query describes exactly the data you need—nothing more, nothing less.
The “Graph” Concept. Treat your data as a connected graph rather than isolated islands. This allows you to fetch a main object (like a User) and its related data (like their Address) in a single request, eliminating the need for multiple round-trips to the server. Predictable Results.
The syntax of the query mirrors the shape of the JSON response. If you request a user with a nested address, the server returns exactly that structure. This predictability makes GraphQL incredibly intuitive and efficient to work with.
The schema is the API Every GraphQL API is defined by a schema. The schema describes the complete data model and all valid operations. It is not optional documentation — it is enforced at runtime. type User { id: ID! name: String! posts: [Post!]! }Because the schema is strongly typed, GraphQL can validate queries before execution. Invalid fields or incorrect arguments fail immediately.
This pushes entire classes of bugs out of production and into development, where they belong. The schema also enables something rare in API design: tooling that actually understands your API. Editors can autocomplete fields, generate types, and validate queries without manual configuration. GraphQL is not a database GraphQL often gets mistaken for a storage layer.
It isn’t. GraphQL doesn’t care where data lives — only how it is shaped and connected. Each field in a query maps to a resolver function. Resolvers are ordinary code. User: { posts: (user, _, ctx) => { return ctx.db.findPostsByUserId(user.id) } }A resolver might hit a SQL database, call a microservice, read from a cache, or combine multiple sources. GraphQL simply orchestrates these calls and assembles the final response. Note: Resolvers are functions that populate the actual data for a single field in your schema.
They are the “implementation layer” that bridges the gap between the client’s requested query structure and your backend data sources, such as databases, external APIs, or microservices. When a client sends a query, the GraphQL server processes it as a tree of fields.
For each field, the corresponding resolver function is called to produce the next value in the response. Why GraphQL changes how teams work One of GraphQL’s biggest advantages isn’t technical — it’s organizational. Frontend teams no longer need new endpoints for every UI change. Backend teams no longer need to anticipate every possible data combination. Fields can be added without breaking existing clients, and different clients can consume the same API in completely different ways. GraphQL optimizes for change, not stability.
That sounds counterintuitive until you’ve worked on a large system where change is the only constant. 𝐋𝐞𝐚𝐫𝐧 𝐭𝐨 𝐛𝐮𝐢𝐥𝐝 𝐆𝐢𝐭, 𝐃𝐨𝐜𝐤𝐞𝐫, 𝐑𝐞𝐝𝐢𝐬, 𝐇𝐓𝐓𝐏 𝐬𝐞𝐫𝐯𝐞𝐫𝐬, 𝐚𝐧𝐝 𝐜𝐨𝐦𝐩𝐢𝐥𝐞𝐫𝐬, 𝐟𝐫𝐨𝐦 𝐬𝐜𝐫𝐚𝐭𝐜𝐡. Get 40% OFF CodeCrafters: https://app.codecrafters.io/join?via=the-coding-gopher This Substack is reader-supported. To receive new posts and support my work, consider becoming a free or paid subscriber.
The tradeoffs nobody leads with GraphQL comes with real costs. Caching is more complex than in REST, where URLs map cleanly to responses. Authorization often needs to happen at the field level rather than the route level. Poorly designed resolvers can cause severe performance issues, including the infamous N+1 query problem.
For small or static APIs, GraphQL can feel like unnecessary machinery. GraphQL doesn’t eliminate complexity — it moves it to the server, where it can be managed centrally. The N+1 query problem The N+1 query problem in GraphQL is a performance anti-pattern that occurs when a server makes one initial query to fetch a list of parent items, and then makes N additional, separate queries to fetch related child data for each individual parent item, rather than fetching all related data efficiently in a single batched query.
This results in a total of N+1 requests, which can lead to significant performance degradation, increased latency, and excessive load on the database or backend APIs as the number of items (N) grows. Example Scenario Imagine you have a GraphQL schema for authors and their books: type Author { id: ID! name: String! books: [Book!]! } type Book { id: ID! title: String! } type Query { authors: [Author!]! }A client might execute a query like this: query { authors { id name books { title } } }On the server side, if not optimized, the execution flow can be inefficient: 1st Query.
A single query fetches all authors (e.g., SELECT FROM authors;). N Queries. For each of the N authors returned, a separate query is executed within the books resolver to fetch their specific books (e.g., SELECT FROM books WHERE authorid = 1; for the first author, SELECT * FROM books WHERE authorid = 2; for the second, and so on). If there are 100 authors, this results in 101 database queries, severely impacting performance compared to an optimized approach. Solution: DataLoaders The most common and effective solution to the N+1 problem in GraphQL is implementing the DataLoader pattern, a utility created by Facebook.
DataLoaders work by: Batching. Instead of executing requests immediately, DataLoaders collect all individual requests for a specific type of data that occur within a short timeframe (usually a single GraphQL request cycle) and combine them into a single, batched query (e.g., SELECT * FROM books WHERE author_id IN (1, 2, 3, ...);). Caching. DataLoaders can cache results per request, ensuring that if the same data is requested multiple times within a single query, it is only fetched once.
By using DataLoaders, the N+1 problem is typically reduced to a 2-query problem (one for the parent items, one batched query for all related child items), regardless of how many parent items are fetched, making the data fetching process scalable and efficient.
Where GraphQL actually shines GraphQL excels in systems dominated by relationships: users connected to content, content connected to interactions, interactions connected to analytics. In these environments, APIs aren’t about resources — they’re about traversing graphs.
This is why GraphQL pairs so naturally with modern product development. It aligns API design with how applications think about data. Final thought GraphQL’s real contribution isn’t syntax. It’s perspective.
It challenges the assumption that servers should dictate how data is consumed. Instead, it treats APIs as typed, queryable data models that clients can shape declaratively. For systems that need to evolve quickly without collapsing under their own APIs, that shift changes everything.
This Substack is reader-supported. To receive new posts and support my work, consider becoming a free or paid subscriber. Thanks for reading! This post is public so feel free to share it. Share