Bump strawberry-graphql[fastapi] from 0.240.4 to 0.241.0
Bumps strawberry-graphql[fastapi] from 0.240.4 to 0.241.0.
Release notes
Sourced from strawberry-graphql[fastapi]'s releases.
🍓 0.241.0You can now configure your schemas to provide a custom subclass of
strawberry.types.Info
to your types and queries.import strawberry from strawberry.schema.config import StrawberryConfig from .models import ProductModel class CustomInfo(strawberry.Info): @property def selected_group_id(self) -> int | None: """Get the ID of the group you're logged in as.""" return self.context["request"].headers.get("Group-ID") @strawberry.type class Group: id: strawberry.ID name: str @strawberry.type class User: id: strawberry.ID name: str group: Group @strawberry.type class Query: @strawberry.field def user(self, id: strawberry.ID, info: CustomInfo) -> Product: kwargs = {"id": id, "name": ...} if info.selected_group_id is not None: # Get information about the group you're a part of, if # available. kwargs["group"] = ... return User(**kwargs) schema = strawberry.Schema( Query, config=StrawberryConfig(info_class=CustomInfo), )
... (truncated)
Changelog
Sourced from strawberry-graphql[fastapi]'s changelog.
0.241.0 - 2024-09-16
You can now configure your schemas to provide a custom subclass of
strawberry.types.Info
to your types and queries.import strawberry from strawberry.schema.config import StrawberryConfig from .models import ProductModel class CustomInfo(strawberry.Info): @property def selected_group_id(self) -> int | None: """Get the ID of the group you're logged in as.""" return self.context["request"].headers.get("Group-ID") @strawberry.type class Group: id: strawberry.ID name: str @strawberry.type class User: id: strawberry.ID name: str group: Group @strawberry.type class Query: @strawberry.field def user(self, id: strawberry.ID, info: CustomInfo) -> Product: kwargs = {"id": id, "name": ...} if info.selected_group_id is not None: # Get information about the group you're a part of, if # available. kwargs["group"] = ... return User(**kwargs) schema = strawberry.Schema( Query, config=StrawberryConfig(info_class=CustomInfo), </tr></table>
... (truncated)
Commits
-
a162c9b
Release🍓 0.241.0 -
7287047
Add ability to set a custom info class for a schema (#3592) -
13bd97b
Remove old link - See full diff in compare view