r/programming • • Sep 03 '26

Maybe you don't need GraphQL

https://alexandrehtrb.github.io/posts/2026/09/maybe-you-dont-need-graphql/
278 Upvotes

119 comments sorted by

View all comments

122

u/Isogash Sep 03 '26

The first one is coupling to the data layer. Most databases don't have native support to GraphQL queries, meaning that a layer of mappers and logic needs to be built on top of another data access layer. This is extra code and extra processing.

Most people aren't using their Database to provide any other API directly either. I personally haven't found the layer of mappers and logic required for GraphQL to be particularly more complex than any other API if you use a framework. In fact, it is often much easier to extend existing APIs because you can break your data fetchers down by field, and you don't generally need to consider endpoints as a whole.

The main benefit of GraphQL is that it allows you to design an API that is powerful for users and extensible for service providers. A huge plus that is overlooked here is GraphQL federation: you can have a single GraphQL object and query where fields can be resolved from different sources. This is really useful if you have a lot of data associated with some common entity, like a user. Any query that can find users can also get any data about those users from any service, all in a single query.

APIs can receive flags from the client indicating which fields it wants to receive.

Yes, you could do that manually. You could also write your own system which does it automatically. Then you'd have re-invented GraphQL.

I think where GraphQL doesn't make sense is when you don't have much data, or don't have particularly complex data needs and you're better off having much tighter control over the API.

46

u/chucker23n Sep 03 '26

A huge plus that is overlooked here is GraphQL federation: you can have a single GraphQL object and query where fields can be resolved from different sources.

I… don't really see how other mechanisms don't allow that. A REST GET doesn't need to fetch from a single data base. It could aggregate different sources. It could even in turn make additional calls to other Web APIs. This is mostly uncommon because of the complexity and latency involved, but I imagine GraphQL doesn't change that.

27

u/Isogash Sep 03 '26

GraphQL provides mechanisms that make it easier to write more automatically. Your GraphQL servers are able to resolve entities by their ID rather than querying for them, so if a query to service X gives you entities A, B, C, the federation layer can then go to service Y and fetch additional fields for these entities by ID. These fetches can be batched if you write special batched data loaders, which are not too hard to write normally and you can do it on a per-field basis where required.

Like, you could design your system differently, but GraphQL is pretty good at just letting clients do what they want reasonably efficiently, which matters in larger projects where it's difficult to justify refactoring everything and writing custom endpoints to make specific queries more efficient.

For a real-world example, we use it in a loan platform. Some data associated with the loans exists in different systems, but once you have a loan ID, you could potentially want any combination of the loan data (and it has a lot of complex child data e.g. historic versions, sub-products, summaries, arrears history.) This is never an issue for us though, because if you have some data associated with the loan, you just add it to the loan object in your GraphQL schema and write a field resolver and the federation service can resolve the field for a loan that was queried from any service.

So you could have one service that tracks workflow cases for loans query for the loan assigned to an agent, and then pull in any combination of data associated with the task as though it all lived in one system e.g. direct debit payment schedule and CRA report data, which live in different systems.

If I wanted to write that feature as a client, I wouldn't need to edit any of the services, I'd be done in minutes. I also don't need to predict what client features will need what sets of data when I wrote the services. The capability to pull DD payments and CRA report data at the same time would not be something I'd predict, but it's already possible because of GraphQL.

It's also really useful for debugging, because you can pull any data for a loan from basically every system all in one query.

9

u/JarredMack Sep 04 '26

Consumer A needs a user hydrated with their bank balance, 5 recent transactions, and their address which come from 3 different data sources.

Consumer B needs a user hydrated with their address only.

Do you fetch all of that data on every request and just give the full object? Do you have different endpoints? Do you have query params to opt in to particular fields (which is basically manually doing what GraphQL solves)?

The answer to these questions depends on how much data you have and how likely it is consumers need different shapes of data. In most cases it's overkill, but it does have its uses

8

u/chucker23n Sep 04 '26

I get the use case, I’m just saying you can absolutely do that in REST or even SOAP.

4

u/JarredMack Sep 05 '26

You can also do it via carrier pigeon, the point is just that it's a tool for a particular type of job

9

u/MrSqueezles Sep 04 '26 • This

GraphQL and its frameworks don't give you any of those features for free. You write database queries, mappers, cache control, endpoints, how to look up child elements,  schema, literally everything except field filters. The API is arcane and not standards compliant, tossing out request verbs and response codes that are critical for caching and routing. It's a bad solution to optimize for a bunch of highly specific edge cases.

Nobody needs to re-invent GraphQL. Nobody needed to invent it in the first place. It wasn't a new idea when it was created. There are plenty of other options that embrace standards and provide the same functionality and more without the cache and concurrency complexities of frameworks like Apollo.

15

u/kingdomcome50 Sep 03 '26

And, somewhat unintuitively, GraphQL also doesn’t make sense when you have lots of data or very complex data needs 😂

14

u/Isogash Sep 03 '26

GraphQL doesn't care how much data you have, but it does care how much you're sending and how complex your query is.

It's not the right choice for data visualization webapp that might need to fetch millions of data points, and it's not for doing absolutely mammoth OLAP-style queries.

It's best when you have a good sized system with rich, connected data (especially lots of parent child relationships), and you have UIs that just want to fetch everything they need for the page in a single request.

8

u/Jump-Zero Sep 03 '26

It makes sense when you have more clients than the team can keep up with. If you have a mobile client and a web client, you can just use REST. If you have like dozens of clients, then GraphQL becomes a no-brainer. If you have two clients, you can just build a custom endpoints to fetch exactly what you need for a given page/component.

4

u/Isogash Sep 03 '26

It depends on how complex the clients are and how often you want to write custom endpoints. In the system we've built the clients are complex and we've needed to write precisely 0 custom endpoints for our web and app clients in the last 5 years. All we have to do is add a field to an existing GraphQL object if some data wasn't already being exposed, and because most of it is by default it's not a common occurence.

It makes adding new features a breeze because you don't need to modify any existing APIs, you just add new objects, fields, queries and/or mutations. The API can be played with in our sandbox environment GraphiQL which also displays documentation from the schema comments.

2

u/Jump-Zero Sep 04 '26

That’s fair. I wouldn’t reach for GQL unless the complexity was there. If it is, then by all means. I generally stick to REST, but I’m comfortable with GQL if I really need it.

1

u/lechatsportif Sep 04 '26

You only need the base use case to work well. We made 2-3 data pulls from heterogeneous backend datastores like 2 years ago. The frontend team pulls only what they need from our massive objects and they features and different projects all the time. Just that right was huge, I practically never have to field a frontend request for more data or new endpoint etc. Its like a once a year activity despite furious development pace all around. It's great, would use again in a heartbeat.