At my place of work we have both REST and GraphQL APIs. I have to maintain and use both regularly. All of our backend development is in Flask (Python), our front ends are Angular and AngularJS (TypeScript).
People post all over the place about how amazing GraphQL is, how it’s the future, the death of REST, all that jazz 🕺. Here are the main points I usually see people bring up in favor of GraphQL over a standard REST API.
- It’s easier to maintain
- Queries are easier to read/write
- You only pull what you need
- It’s interactive (with something like GraphiQL)
- You can craft a single request to get all the data you need
- Easy to generate documentation
There’s my bias, I’m wearing it on my sleeve. Here are my counterpoints.
- It’s not easier to maintain, at least not in my experience. I have to write more code in more locations to add something to a GraphQL API than a REST one.
- They’re easier to read and write in tools that are designed to do so, but they are hard to parse when in a big string blob (as they always end up being when consumed). Meanwhile in REST land I can have Swagger generate native code (TypeScript for me) that gives me all the models and services.
- You only pull what you want from a good REST API too, using something like X-Fields
- Swagger UI on the server doing the serving is at least as easy and interactive.
- Yeah but I’ve never come across a situation where you only need one query anyway, or where it’d make a noticeable difference.
- Again, not in my experience. Flask-RESTPlus generates docs based on comments... that’s pretty easy.
I also have further reasons I like REST more:
A. You can only do CRUD with GraphQL, there’s more to APIs than that.
B. The tooling for GraphQL is very lackluster (or maybe just young?) especially when consuming such an API.
I don’t want to be so fully in the camp of REST, I want to understand why people love GraphQL. Are we just doing it wrong? Is it that Graph is amazing on Node and React, and not on the techs we use? Am I a curmudgeon 👴🏻? Please let me know.