graphql-python / flask-graphql

Adds GraphQL support to your Flask application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to create a session per query?

impguard opened this issue · comments

Using SQLAlchemy and my current process of creating database sessions revolve around a context manager and a session factory.

AKA in a RESTful API I would do something like this:

def someroute():
    with session_factory() as session:
        ...do some controller stuff with the session...
        return result

Since Graphene/GraphQL seems to wrap a lot of the magic around querying, how do I inject the session I create dynamically on a query/mutation request?

It seems like the model expected here is to have a persistent database session? Am I correct in assuming this?

P.S. I originally opted for this model since I wanted to contain all database side-effecty stuff in one python module instead of having to hook into my backend request teardown loop to handle cleaning up sessions.

Sorry wrong project since both tabs are up. I'll close this.