News for hackers. Stuff that matters.
Re:On GraphQL-to-SQL by fb03 on Friday May 22, 2020 @11:03AM (#23272838)
Shameless Plug here:

I have developed a Python library that does essentially this GraphQL-to-SQL pattern, leveraging the power of SQLAlchemy and some metaprogramming to create the 4 CRUD methods for each table automatically, all with filters, orderby, pagination and subrelationships/queries. And if you use SQLAlchemy's automap, you don't even have to have the database schema ready.

I needed this when a client with a huge Microsoft SQL Server database (2k tables+) asked me to quickly export it 'to the web' with the least friction possible. I researched Hasura and it was available only for PGSQL, so I created my own, and by using SQLAlchemy I can connect with any database supported. I am using pyODBC with Microsoft's drivers on Linux and I can easily connect to the database and export it.

I am gonna provide example code soon'ish on the library's repo. But basically, it goes:

# Instantiate the library, pass in your db url and your SQLAlchemy database schema (declarative_base() or automap_base())

# GraphQL objects, schema and actual crud functions leveraging the passed connection_string get dynamically generated.

# Instantiate a GrapQLView, and pass it to your Flask App()

# That's it!

https://github.com/flipbit03/sqlalchemy-graphql-schemagen

There are no comments on this comment yet.