How to store/fetch global data within the resolver #562
|
I would like to attach my async initialized object(for example a connection pool) in the |
Replies: 2 comments 6 replies
|
FWIW - what I did for development purposes was to allocate an AppConfig object with an async callable that sets up the connection pool. In ariadne/asgi.py, when handling a http request, it sets up the context by looking for the (async) callable property. This allows you to execute any awaitable functions from within your AppConfig. Along the lines of - All that said, I have yet to find a best practice for setting up the info.context for caching session objects. I haven't tested in detail the above approach and first blush is I'm concerned about how this behaves with a theaded pool / concurrency across sessions. In my mind, AppConfig should be a global singleton object supporting re-entrancy across sessions but that's above my pay grade at the moment. |
FWIW - what I did for development purposes was to allocate an AppConfig object with an async callable that sets up the connection pool. In ariadne/asgi.py, when handling a http request, it sets up the context by looking for the (async) callable property. This allows you to execute any awaitable functions from within your AppConfig.
Along the lines of -