Dishka integration for Strawberry
Project description
Strawberry
Though it is not required, you can use dishka-strawberry integration. It features:
- automatic injection of dependencies into GraphQL resolver functions
- integration with FastAPI through
strawberry.fastapi.GraphQLRouter
Installation
Install using pip:
pip install dishka-strawberry
Or using uv:
uv add dishka-strawberry
How to use
1. Import
from dishka_strawberry.fastapi import (
FromDishka,
inject,
)
from dishka.integrations.fastapi import (
FastapiProvider,
setup_dishka,
)
from dishka import make_async_container, Provider, provide, Scope
2. Create provider
You can use FastapiProvider as a base class if you need to access fastapi.Request in your providers
class AppProvider(FastapiProvider):
@provide(scope=Scope.REQUEST)
def create_message(self) -> Message:
return Message("42")
3. Mark resolver parameters
Mark resolver parameters which are to be injected with FromDishka[] and decorate them using @inject
@strawberry.type
class Query:
@strawberry.field
@inject
def answer(self, message: FromDishka[Message]) -> MessageGQL:
return MessageGQL(message=message)
4. Create Strawberry schema
Create Strawberry schema and integrate it with FastAPI using GraphQLRouter
schema = strawberry.Schema(query=Query)
graphql_router = GraphQLRouter(schema)
app = FastAPI()
app.include_router(graphql_router, prefix="/graphql")
5. Setup dishka integration
Setup dishka integration for FastAPI (which will handle the container lifecycle for GraphQL requests as well)
container = make_async_container(AppProvider())
setup_dishka(container=container, app=app)
Contributing
Contributors are welcome! If you'd like to contribute to this project, please feel free to open an issue or submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dishka_strawberry-0.1.1.tar.gz.
File metadata
- Download URL: dishka_strawberry-0.1.1.tar.gz
- Upload date:
- Size: 64.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a830be55707692817897634fc4c825f23a8424d8b06e369c640b6546dc5bf8ac
|
|
| MD5 |
7ebfc19e7fd81e6b0f8079106099f6b6
|
|
| BLAKE2b-256 |
f83ef79f4656368d4fdb63d1f736402fa4985e457e9d5c406a4dbaa3d15c51cf
|
File details
Details for the file dishka_strawberry-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dishka_strawberry-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03cb52e3c4261687480e4516dd3bdc55e88b1db9632c1e6cc0afff7ded5e884f
|
|
| MD5 |
e89716d02b67d0cd2c6aacdc66f68bc3
|
|
| BLAKE2b-256 |
3bf5c48fa6c989bc97230d1189c0bce94d891ecb068a4160d182146e6b69c91a
|