2 ms·
Indeed in most cases replacing simple code with GraphQL only adds complexity. The old approach has been more like this: [client] <- RESTful request -> [your
by akrymski 4y ago
Indeed in most cases replacing simple code with GraphQL only adds complexity.
The old approach has been more like this:
[client] <- RESTful request -> [your API] <- Your data fetching logic -> [DB] <- SQL query (with parameters) -> [DB]
Replacing your data fetching logic with GraphQL just means translating your JS/Python to GraphQL - something that isn't as flexible, turing complete, or predictable (in execution).
If anything, I'd prefer to go the other way and get rid of SQL altogether - let me express queries in code:
books.filter(book => book.author === "Alice")
.group(book => book.year)
.map(group => group.reduce(({ sum = 0 }, { year, sales }) => ({ year: year, sales: sum + sales }), {}))
.sort((a, b) => b.year - a.year)
which translates to:
SELECT year, SUM(sales) FROM books WHERE author = 'Alice' GROUP BY year ORDER BY year DESC
but is far more composable, debuggable and potentially more deterministic - I'd like more control over query execution planner, not less.