DEV Community

Dylan Anthony
Dylan Anthony

Posted on

[Discussion] Why GraphQL?


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.

Top comments (2)

rhymes profile image
rhymes • Edited

I think the two main reasons for the GraphQL hype are the ability to get a subset of fields in a standard way (there's no standard in REST, every API is slightly different) and easily write interfaces on multiple REST APIs exposing them as a singular GraphQL API.

I don't think REST is going anywhere, but neither is GraphQL. We'll have to live with both for many years :)

After all SOAP APIs are still around

xalitech profile image
Xali Tech

Dylan, very good post on GrphQL,to anser why Graphql I wrote on GraphQL: How to convince your boss?

Check that out!