r/graphql • u/gsvclass • Feb 28 '21
Why REST is terrible and GraphQL a game changer.
Disclaimer:
I'm the author of GraphJin https://github.com/dosco/graphjin
This is an opinion piece therefore it is my subjective opinion.
I use both REST and GraphQL
I've spent years building products with REST APIs and it's always felt like I'm forcing a square peg into a round hole Everything with REST is a a struggle and cognitive drain, mapping HTTP error codes to your response types, picking between PUT, PATCH and POST, coming up with URL path names, resource vs view specific APIs, having to build batch APIs, coming up with url paths for these APIs and the worst of them all inventing a query and filtering language that you then have to squeeze into a url query string.
People say REST is a standard but that not really true, it's not. I feel I've seen every possible liberty taken by those building with REST including once where someone was using GET requests for backend database mutations and don't even get me started with HTTP error codes.
Even when starting off with a popular framework this complexity catches up and you often end up writing a ton of database code for every operation on every resource and then having to maintain all of that to eternity. To add to this work load the API is constantly changing to meet the demands of rich and fast changing product interfaces. You're always blocking someone and this takes a toll. Soon tech debt starts to creep in, let's just add this one off param here and let's just break out rules there.
GraphQL is a breadth of fresh air or like Steve Jobs puts it a bottle of cold water to someone in hell. GraphQL is exactly what 90% of app development is about - querying the exact data you need. It is a language for writing queries. REST is a fancy name given to HTTP and is best for when you want to send HTML back and forth. Building with REST vs GraphQL feels like using a CSV file vs a real database for managing your data.
To me the best thing to come out of the GraphQL world is the GraphQL to SQL compilers like GraphJin, Hasura and Postgraphile. I used GraphJin to build 42papers.com and besides spending a day on the database schema I literally had zero backend code to write. My entire focus could now be on the experience and building the web UI that touches users. It was almost magical to be able to just write out a GraphQL query when building a view and have all the data I need. This focus gave me the freedom to build a better product, iterate faster and bring my vision to life instead of trying to figure out what HTTP error code is the right one.
Any startup using a GraphQL to SQL compiler like GraphJin or Hasura will run circles around those who don't. And as the database improves the new capabilities will be automatically leveraged by these compilers to generate more efficient queries. Features like rate-limiting, tracing, compression all comes out of the box and continue to improve without you having to change a line of code. Even capabilities that I would not have dreamed of like efficiently subscribing to database changes from the browser are as simple as using the word `subscription` instead of `query` in your GraphQL.
GraphQL makes all of this possible it frees your developers from doing boring boilerplate work and instead focus on the meaty and valuable parts of your app. I'm glad I don't have to waste time on something commodity like manually writing SQL queries to a database and instead have the computer do it for me. To build better products developers happiness is as important as the user happiness.
The projects mentioned in this post
GraphJin
https://github.com/dosco/graphjin
Hasura
https://github.com/hasura/graphql-engine
Postgraphile