nalzok posted an interesting question over a year ago: "Why not use SQL instead of GraphQL?".
Respondents seem to suggest three main problems:
- One should not directly expose one's database to external users.
- SQL is too powerful to allow external users to have direct access.
- This exposes the internal structure of one's database.
I'd like to piggy-back on this question by asking why not use SQL as the query language for an API instead of GraphQL.
Here is my high-level understanding of direct SQL, GraphQL, and (theoretical) SQL API functioning:
- Direct SQL: External User --> SQL Query --> Database
- GraphQL: External User --> GraphQL --> Database
- (Theoretical) SQL API: External User --> TheoreticalSQLAPI --> Database
TheoreticalSQLAPI would seem to resolve all three of the major problems listed above:
- The database is not directly exposed.
- Can be restricted to a subset of SQL.
- Need not be a direct mapping of the internal database structure, it could be abstracted.
The one advantage I've seen mentioned for GraphQL is that it is not restricted to querying databases but can query any type of data - but this would seem to be a fairly minor problem for SQL since it has been implemented as a query mechanism for a wide variety of data formats.
Is the answer simply that no one has created a popular implementation? Are there other advantages GraphQL offers over SQL?
I'm probably only asking this question b/c I've been writing SQL for ~20 years and GraphQL seems like yet another technology to master.