Skip to content

How to store/fetch global data within the resolver #562

Discussion options

You must be logged in to vote

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 -

class AppConfig:
  _initialized: bool = False

  @property
  def connectionPool(self)->Pool:
    # returns a handle to your connection pool

  async def __call__(self, request: Any)->Any:
    # Initialize your awaitables here
    if not self._initialized 
      try:
        await self.initialize()  # set up your connection pool, cached obje…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@zhqu1148980644
Comment options

Answer selected by zhqu1148980644
Comment options

You must be logged in to vote
5 replies
@zhqu1148980644
Comment options

@glennlaughlin
Comment options

@rafalp
Comment options

@glennlaughlin
Comment options

@rafalp
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants