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 |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
-
To be fair, it is documented here and here. But I would love to see an example or best practice for using it especially in the context of connection pooling and/or session caches. The above seems to work in my local test environment but in production? |
Beta Was this translation helpful? Give feedback.
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 -