All the articles about GraphQL will tell you how wonderful it is, but are there any disadvantages or shortcomings to it? Thank you.
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.
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.
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.
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.
Disadvantages:
But, those are more than countered by these:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With