diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f688b55ff..d7124035ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,62 @@ 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. + +```py +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), +) +``` + +Contributed by [Ethan Henderson](https://github.com/parafoxia) via [PR #3592](https://github.com/strawberry-graphql/strawberry/pull/3592/) + + 0.240.4 - 2024-09-13 -------------------- diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index 2a3ac6f238..0000000000 --- a/RELEASE.md +++ /dev/null @@ -1,51 +0,0 @@ -Release type: minor - -You can now configure your schemas to provide a custom subclass of -`strawberry.types.Info` to your types and queries. - -```py -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), -) -``` diff --git a/pyproject.toml b/pyproject.toml index 900a7c5ca7..d54e8cebca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "strawberry-graphql" packages = [ { include = "strawberry" } ] -version = "0.240.4" +version = "0.241.0" description = "A library for creating GraphQL APIs" authors = ["Patrick Arminio "] license = "MIT"