backend.ai icon indicating copy to clipboard operation
backend.ai copied to clipboard

Apply Fetcher Pattern to Strawberry GraphQL Resolvers

Open jopemachine opened this issue 3 weeks ago • 0 comments

Motivation

Currently, some GraphQL resolvers use delayed imports within resolver functions to prevent cyclic imports. This pattern reduces code readability and mixes business logic with resolver definitions, making maintenance difficult.

By introducing fetcher.py in the artifact module and separating data fetching logic, we achieved:

  • Resolution of cyclic import issues

  • Resolvers focus only on request handling/routing

  • Fetchers focus only on data retrieval logic

  • Type definition files (types.py) can safely import fetchers

    We aim to apply this pattern consistently across other Strawberry GraphQL modules to improve codebase consistency and maintainability.

Objective

Apply the fetcher pattern to all non-federated Strawberry GraphQL modules under src/ai/backend/manager/api/gql/:

  • Create fetcher.py file for each module
  • Separate data retrieval logic from resolvers into fetchers
  • Rename resolve_* functions to fetch_* and move them
  • Move pagination spec helper functions to fetchers

Expected Sub Issues

  • [ ] Apply fetcher pattern to huggingface_registry module
  • [ ] Apply fetcher pattern to reservoir_registry module
  • [ ] Apply fetcher pattern to scaling_group module
  • [ ] Apply fetcher pattern to notification module
  • [ ] Apply fetcher pattern to model_deployment module
  • [ ] Apply fetcher pattern to storage_namespace module
  • [ ] Apply fetcher pattern to object_storage module
  • [ ] Apply fetcher pattern to vfs_storage module
  • [ ] Apply fetcher pattern to scheduler module
  • [ ] Apply fetcher pattern to background_task module
  • [ ] Apply fetcher pattern to agent_stats module
  • [ ] Apply fetcher pattern to app_config module
  • [ ] Apply fetcher pattern to artifact_registry module
  • [ ] Apply fetcher pattern to artifact_registry_meta module

JIRA Issue: BA-3494

jopemachine avatar Dec 19 '25 02:12 jopemachine