Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any disadvantages to GraphQL? [closed]

All the articles about GraphQL will tell you how wonderful it is, but are there any disadvantages or shortcomings to it? Thank you.

like image 271
Dr.Nemo Avatar asked Nov 19 '16 06:11

Dr.Nemo


People also ask

Are there any disadvantages to GraphQL?

While GraphQL has many advantages over traditional REST APIs, there are several key disadvantages as well. One disadvantage is that queries always return a HTTP status code of 200 , regardless of whether or not that query was successful.

What is the biggest disadvantage from using GraphQL?

GraphQL is more complex than REST, and its main drawbacks include issues with error reporting, caching, and N+1. However, GraphQL solves the over and under-fetching problem that REST has, is protocol agnostic and has a quick response time.

What are the problems with GraphQL?

GraphQL makes some tasks more complex For example, in an application that uses a few fields the same way each time, using GraphQL adds more complexity because of things like types, queries, mutators, resolvers, and higher-order components, From a maintenance perspective, this is especially detrimental.

Is GraphQL still relevant 2022?

The only large complexity left in GraphQL, with no library to solve it yet, is the deep nesting and recursion in complex quires. But as long as your application won't require any super complex fetches and you use GraphQL correctly, I strongly encourage you to obtain the many benefits of using GraphQL in your project.


2 Answers

Disadvantages:

  • You need to learn how to set up GraphQL. The ecosystem is still rapidly evolving so you have to keep up.
  • You need to send the queries from the client, you can just send strings but if you want more comfort and caching you'll use a client library -> extra code in your client
  • You need to define the schema beforehand => extra work before you get results
  • You need to have a graphql endpoint on your server => new libraries that you don't know yet
  • Graphql queries are more bytes than simply going to a REST endpoint
  • The server needs to do more processing to parse the query and verify the parameters

But, those are more than countered by these:

  • GraphQL is not that hard to learn
  • The extra code is only a few KB
  • By defining a schema, you will prevent much more work afterwards fixing bugs and enduring hairy upgrades
  • There are a lot of people switching to GraphQL so there is a rich ecosystem developing, with excellent tooling
  • When using persistent queries in production (replacing GraphQL queries with simply an ID and parameters), you actually send less bytes than with REST
  • The extra processing for incoming queries is negligible
  • Providing a clean decoupling of API and backend allows for much faster iteration on backend improvenments
like image 78
w00t Avatar answered Sep 28 '22 15:09

w00t


I have found some important concerns for anyone considering using GraphQL, and up until now the main points are:

Query In Indefinite Depth: GraphQL cannot query in indefinite depth, so if you have a tree and want to return a branch without knowing the depth, you’ll have to do some pagination.

Specific Response Structure: In GraphQL the response matches the shape of the query, so if you need to respond in a very specific structure, you'll have to add a transformation layer to reshape the response.

Cache at Network Level: Because of the commonly way GraphQL is used over HTTP (A POST in a single endpoint), cache at network level becomes hard. A way to solve it is to use Persisted Queries.

Handling File Upload: There is nothing about file upload in the GraphQL specification and mutations doesn’t accept files in the arguments. To solve it you can upload files using other kind of APIs (like REST) and pass the URL of the uploaded file to the GraphQL mutation, or inject the file in the execution context, so you’ll have the file inside the resolver functions.

Unpredictable Execution: The nature of GraphQL is that you can query combining whatever fields you want but, this flexibility is not for free. There are some concerns that are good to know like Performance and N+1 Queries.

Super Simple APIs: In case you have a service that exposes a really simple API, GraphQL will only add an extra complexity, so a simple REST API can be better.

like image 25
Bruno Soares Avatar answered Sep 28 '22 15:09

Bruno Soares