Support dependency injection in resolvers
In my use case, I have a public GraphQL API and private FastAPI API, both running on the same webserver and sharing some internal logic, so I'd like to be able to reuse my dependencies between them.
Ideally, I'd like to do something like this:
from fastapi import Depends
def some_resolver(
session_maker = Depends(session_maker),
store = Depends(store)
):
async with session_maker() as session:
return store.search(session=session)
or this:
from dependency_injector.wiring import Provide, inject
@inject
def some_resolver(
session_maker = Provide[Container.session_maker],
store = Provide[Container.store]
):
async with session_maker() as session:
return store.search(session=session)
Currently, when trying any of those dependency injection methods, graphql/type/definition.py
raises TypeError: Query fields cannot be resolved. Unexpected type...
.
I know I can pass my custom dependencies using GraphQLRouter's context_getter
param, but that solution sacrifices typehinting.
Is it feasible for Strawberry to stop treating function params as graph query params when they are not strawberry
types? Or approaching it from other direction, is it possible to introduce a way to 'mark' some params, so they are not treated as query params?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too