Are there any disadvantages to GraphQL? [closed]

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

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.