As a developer working with Graph-like APIs and SQL databases, I often wished for an easy way to parse $filter, $select, and similar query strings and convert them into SQL. So I built gq-to-sql — a lightweight, safe utility for just that.
Features
✅ Parse Graph-style query strings: $filter, $select, $orderby, $top, $skip
✅ Safe SQL output with parameters (?)
✅ Nested condition support ((age gt 20 or age lt 10))
Example
Input:
?$filter=age gt 20 and city eq 'Vienna'&$select=name,age&$orderby=age desc
Output:
SELECT name, age FROM users WHERE age > ? AND city = ? ORDER BY age desc
Try It Out
npm install gq-to-sql
👉 View it on GitHub: https://github.com/masem1899/graphql-to-sql
👉 Website: https://masem.at/s/devto
👉 Blog Article: https://www.masem.at/blog/introducing-gqtosql-graphstyle-url-filtering-for-sql
Top comments (3)
I understand the convenience of a tool like that. But as a backend specialized developer I'm not comfortable with directly linking user input with SQL. it is a whole lot of power you give to the people that visit your website.
Is it possible you didn't make the repository public? I get a 404 when I click on the link. And i don't see it on your profile.
Hi, it's public now.
pretty cool honestly, stuff like this saves headaches for me- ever run into weird edge cases with complex nested filters or does it handle those fine?