graphql-python / flask-graphql

Adds GraphQL support to your Flask application.
MIT License
1.32k stars 140 forks source link

How to create a session per query? #8

Closed impguard closed 8 years ago

impguard commented 8 years ago

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.

impguard commented 8 years ago

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