3
6 Comments

GraphQL changed my world!

First time in a project admin panel, I decided to use GraphQL to manage requests to provide all the data needed to render a page. It was amazing!
Requests count decreased and I dropped many processes for data in frontend with no pain in the backend. Also made it possible to show different information from different services easily.

Recently we had a freelance project and I suggested using GraphQL instead of REST API. Again AMAZING.
It decreased the complexity to provide data.
It was easier to design the API.
There was no need to add help or something like Swagger.

After these experiences, I prefer GraphQL to REST in almost all cases, because:

  • GraphQL is self-documented
  • with GraphQL you can omit object fields easily, so you don't get unnecessary data
  • you can use join on data in GraphQL, not database. it is very useful when you have separate services
  • with GraphQL you can decrease your API calls to 1
  • GraphQL has an amazing client (https://www.apollographql.com/)
  • with GraphQL you can have parameters on fields. for example format for DateTime, or unit for dimensional numbers
  • with GraphQL you can provide different data views easier. REST API is terrible at it, most times you need to define a new route for every use case
  • with GraphQL you make your API repository layer simpler
  • with GraphQL you can develop faster (back + front)
  • with GraphQL you can integrate third-party APIs to yours.
  • with GraphQL you can use aliases for your response data. it is good for the frontend because you can immediately pass the response to your objects without iterating.
  • with GraphQL there is no need for API Versioning.
  • with GraphQL you can tell permission requirements in documentation.

Also, I had these problems with GraphQL:

  • There is no official upload solution. So I use upload via REST.
  • I use RFC7807 (https://tools.ietf.org/html/rfc7807) for REST APIs, but still have problems managing errors in GraphQL.

Let me know if you find more pros and cons for GraphQL.

on January 3, 2021
  1. 1

    Can you recommend any good online tutorials/books for absolute beginners to GraphQL? Or anything in the league of "GraphQL for Rest API developers"?

    1. 1

      for learning GraphQL you should read the main site: https://graphql.org/learn/
      But, for using, it depends on the programming language you use!
      Maybe it helps you: https://www.howtographql.com/
      Also, feel free to ask me if you have any question in this road

  2. 1

    I wholeheartedly agree! I'm just learning JS and was looking at creating APIs for my app. I looked at REST and GraphQL and as a complete beginner, GraphQL was a no brainer.
    I even have file upload working using GraphQL. Apollo has built in support for it: https://www.apollographql.com/blog/file-uploads-with-apollo-server-2-0-5db2f3f60675/

    1. 2

      Also, I use Golang for backend. So I can't use Apollo Server ;)

    2. 1

      Yes, they have support for upload. But there is no official upload solution in GraphQL specs for upload