Hacker News new | ask | show | jobs
by vanshg 1412 days ago
Isn't this exactly what SQL is supposed to be for? Why not just submit SQL queries and get the response directly from the DB?

That is to say, what differentiates GraphQL from SQL?

2 comments

GraphQL is a layer in front of SQL.

I can write a Graphql endpoint in python (Using Django-Graphene). I can write python functions that return data to the graphql. I can write ORM queries that write data to grapqhl. I can specify access, permissions and certain queries based on the user.

Graphql is more of a relational FFI than a SQL replacement.

Also the frontend never sends SQL to get data because it is unsafe. This is what a GraphQL framework allows you to do, clean up and filter queries so they are safe and then translate them into efficient lookups in a RDBMS.

SQL is a leaky abstraction, which makes your system more brittle. The front-end now has intimate knowledge about the physical data management. You don't want that. If later you decide you want to change your physical data layout to improve data storage and retrieval performance then your queries have to be modified. The front-end and data tier can't vary independently from one another. That's what makes your system brittle.

That's not even getting into the tremendous attack surface you've just opened leaving your application vulnerable to SQL injection attacks. SQL injection is a real problem and scrubbing all the inputs is a pain and you can never be sure you got everything. One mistake and congratulations! - you've made headline news!

These are the problems GraphQL solves.