diff --git a/CHANGELOG.md b/CHANGELOG.md index 087baa9382..dca3c03778 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,44 @@ CHANGELOG ========= +0.218.0 - 2024-01-22 +-------------------- + +This release adds a new method `get_fields` on the `Schema` class. +You can use `get_fields` to hide certain field based on some conditions, +for example: + +```python +@strawberry.type +class User: + name: str + email: str = strawberry.field(metadata={"tags": ["internal"]}) + + +@strawberry.type +class Query: + user: User + + +def public_field_filter(field: StrawberryField) -> bool: + return "internal" not in field.metadata.get("tags", []) + + +class PublicSchema(strawberry.Schema): + def get_fields( + self, type_definition: StrawberryObjectDefinition + ) -> List[StrawberryField]: + return list(filter(public_field_filter, type_definition.fields)) + + +schema = PublicSchema(query=Query) +``` + +The schema here would only have the `name` field on the `User` type. + +Contributed by [Patrick Arminio](https://github.com/patrick91) via [PR #3274](https://github.com/strawberry-graphql/strawberry/pull/3274/) + + 0.217.1 - 2024-01-04 -------------------- diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index 02cd81b71c..0000000000 --- a/RELEASE.md +++ /dev/null @@ -1,33 +0,0 @@ -Release type: minor - -This release adds a new method `get_fields` on the `Schema` class. -You can use `get_fields` to hide certain field based on some conditions, -for example: - -```python -@strawberry.type -class User: - name: str - email: str = strawberry.field(metadata={"tags": ["internal"]}) - - -@strawberry.type -class Query: - user: User - - -def public_field_filter(field: StrawberryField) -> bool: - return "internal" not in field.metadata.get("tags", []) - - -class PublicSchema(strawberry.Schema): - def get_fields( - self, type_definition: StrawberryObjectDefinition - ) -> List[StrawberryField]: - return list(filter(public_field_filter, type_definition.fields)) - - -schema = PublicSchema(query=Query) -``` - -The schema here would only have the `name` field on the `User` type. diff --git a/pyproject.toml b/pyproject.toml index bacd7737aa..e1349c9ca4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "strawberry-graphql" packages = [ { include = "strawberry" } ] -version = "0.217.1" +version = "0.218.0" description = "A library for creating GraphQL APIs" authors = ["Patrick Arminio "] license = "MIT"