Sqlmancer - translate GraphQL queries into SQL statements
Tags: sql, graphql, showdev, beginners
Published: 2020-07-31 06:46:22

Since its open-sourcing, GraphQL keeps on gaining popularity and is becoming used by more & more development teams. Why? What's its secret? It's simple, GraphQL makes describing the complex data dependencies easy and it can be usee with any programming language. The rising popularity created a demand for different tools and libraries facilitating GraphQL implementation & usage across different technologies and vice-versa. **Sqlmancer** is one of them.

## Goals & Features

Sqlmancer is a Node.js library simplifying GraphQL integration with SQL by translating GraphQL queries into SQL statements in a smart way. The flexibility offered by Sqlmancer allows you to create the queries and mutations that suit your schema as well as leaving the decisions to you what types you want to expose in your schema by offering a number of convenient directives. The last but not least, Sqlmancer put annotation over transformation using directives mostly to annotate your schema rather than changing its behavior, aiming to be as aspect-oriented as possible.

Some of the notable features of Sqlmancer:
- **Various dialects supported** - you can incorporate Sqlmancer into existing projects regardless of what flavor of SQL you're using as it supports Postgres, MySQL, MariaDB, and SQLite.

- **Advanced sorting & filtering** - Add complex sorting and filtering to your data-fetching, including:
  - filtering using logical operators,
  - filtering and sorting by fields
  - filtering by aggregate fields of related models.

- **Performance** - Sqlmancer makes the N+1 problem the song of the past by building a single SQL query to fetch all necessary data, regardless of query depth.

- **Custom scalars & Abstract types** - Use the scalars that make sense and easily add unions and interfaces into your schema using views or single table inheritance features.

## How it works

Sqlmancer generates a type-safe database client basing on your GraphQL schema and metadata provided through a set of schema directives, giving you the ability to query your server for complex data structures with a single SQL query:

![Sqlmancer sample resolver](https://dev-to-uploads.s3.amazonaws.com/i/m3g2ycgw1d85rjllcipc.png)
##### Source: [sqlmancer.netlify.app](https://sqlmancer.netlify.app/introduction)

while keeping your resolver as simple as possible:

![Sqlmancer sample query](https://dev-to-uploads.s3.amazonaws.com/i/8yikcw8abvb2txbmtdcg.png)

##### Source: [sqlmancer.netlify.app](https://sqlmancer.netlify.app/introduction)

Cool, right? If you are interested in for a detailed guide on how to work with the library make sure to visit [official Sqlmancer documentation](https://sqlmancer.netlify.app/introduction) 

## Still in development 

Sqlmancer is still in development. The API is still subject to changes so be aware that there might be some breaking changes coming anytime. As mentioned by the creator feedback and suggestions from the community are more than welcome so if you find a bug, have a feature request, or just want to contribute to this awesome project, feel free to an open issue.

---

## Speed up your GraphQL API development

*GraphQL Editor* is a supportive tool for both advanced GraphQL users as well as those taking their first steps with GraphQL APIs. Our all-in-one development environment for GraphQL will help you build, manage & deploy your GraphQL API much faster. **[Try GraphQL Editor for free!](https://graphqleditor.com)**


[![GraphQL Editor](https://res.cloudinary.com/practicaldev/image/fetch/s--XhJnT9d1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/835ac1nun474qfgn1tfi.gif)](https://graphqleditor.com/)