can I write custom sql with graphene-sqlalchemy?

246 Views Asked by At

Can we write custom sql with graphene-sqlalchemy to retrieve data? My output is not present in a database table directly but is built using 'CTEs'.

Background: I'm trying to build a graphql backend in python. The purpose is that this graphql backend layer will act as an API layer. And if I have to switch between different datasources, all I would do is change the connection string and everything else would remain same.

Summary: My graphene models will have to be built off of database views and not database tables. I will only be querying the data and not performing any mutations.

I want my data resolvers need to run dynamic queries (based on inputs passed) on tables and then aggregate data and return results. Because of the this aggregations happening on the fly based on inputs I cannot pre-aggregate the data and store in tables. So I want to execute this dynamic sql against tables.

Table-Tasks has 3 columns: id name user_id

Table Issues has 4 columns: id task_id issue_status user_id

So I will build views A and B (lets say) on these tables based on the inputs I get and then do aggregations on these views. So an ability to write custom sql for my resolvers will help a lot. Is that possible in graphene-sqlalchemy?

0

There are 0 best solutions below