Using a single session with FastAPI
See original GitHub issueI have a Hasura GraphQL engine as a server with a few small services acting like webhooks for business logic and handling database events. One of theses services has a REST API and needs to retrieve data from the GraphQL engine or run mutations. Due to performance concerns I have decided to rewrite one of the services with FastAPI in order to leverage async.
I am quite new to async in Python in general which is why I took my time to go through gql documentation.
It is my understanding that it is ideal to keep a single async client session throughout the life span of the service. It is also my understanding that the only way of getting an async session is using the async with client as session:
syntax.
That poses the question of how can I wrap the whole app inside of the async with
. Or perhaps I am missing something and there is a better way of doing this.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:11
Top GitHub Comments
This should be made easier.
After the stable version has been done, I propose to add a new interface to create permanent sessions:
Hi @leszekhanusz, thank you for your awesome work.
I tested (stress test) it with my FastAPI project and it solve all of the session handling Thank you very much!
I’m looking forward to the official release
(I used https://locust.io/ for the stress test)