[Discussion] Why GraphQL?

Dylan Anthony - Apr 26 '19 - - Dev Community

Background

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).

What I know

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.

  1. It’s easier to maintain
  2. Queries are easier to read/write
  3. You only pull what you need
  4. It’s interactive (with something like GraphiQL)
  5. You can craft a single request to get all the data you need
  6. Easy to generate documentation

I prefer REST 😴

There’s my bias, I’m wearing it on my sleeve. Here are my counterpoints.

  1. 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.
  2. 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.
  3. You only pull what you want from a good REST API too, using something like X-Fields
  4. Swagger UI on the server doing the serving is at least as easy and interactive.
  5. Yeah but I’ve never come across a situation where you only need one query anyway, or where it’d make a noticeable difference.
  6. 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.

Please help

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player