Introducing gq-to-sql: Convert Graph-Style URL Queries into SQL
sempre76

sempre76 @huetteldorf

Location:
Austria
Joined:
Jan 29, 2020

Introducing gq-to-sql: Convert Graph-Style URL Queries into SQL

Publish Date: Jun 18
4 3

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

Comments 3 total

  • david duymelinck
    david duymelinckJun 18, 2025

    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.

    • sempre76
      sempre76Jun 18, 2025

      Hi, it's public now.

  • Nevo David
    Nevo DavidJun 18, 2025

    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?

Add comment