diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3179ab34..31d853a40f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,64 @@ CHANGELOG ========= +0.217.0 - 2023-12-18 +-------------------- + +Permissions classes now use a `FieldExtension`. The new preferred way to add permissions +is to use the `PermissionsExtension` class: + +```python +import strawberry +from strawberry.permission import PermissionExtension, BasePermission + + +class IsAuthorized(BasePermission): + message = "User is not authorized" + error_extensions = {"code": "UNAUTHORIZED"} + + def has_permission(self, source, info, **kwargs) -> bool: + return False + + +@strawberry.type +class Query: + @strawberry.field(extensions=[PermissionExtension(permissions=[IsAuthorized()])]) + def name(self) -> str: + return "ABC" +``` + +The old way of adding permissions using `permission_classes` is still +supported via the automatic addition of a `PermissionExtension` on the field. + +Using the new `PermissionExtension` API, permissions support even more features: + +#### Silent errors + +To return `None` or `[]` instead of raising an error, the `fail_silently ` keyword +argument on `PermissionExtension` can be set to `True`. + +#### Custom Error Extensions & classes + +Permissions will now automatically add pre-defined error extensions to the error, and +can use a custom `GraphQLError` class. This can be configured by modifying +the `error_class` and `error_extensions` attributes on the `BasePermission` class. + +#### Customizable Error Handling + +To customize the error handling, the `on_unauthorized` method on +the `BasePermission` class can be used. Further changes can be implemented by +subclassing the `PermissionExtension` class. + +#### Schema Directives + +Permissions will automatically be added as schema directives to the schema. This +behavior can be altered by setting the `add_directives` to `False` +on `PermissionExtension`, or by setting the `_schema_directive` class attribute of the +permission to a custom directive. + +Contributed by [Erik Wrede](https://github.com/erikwrede) via [PR #2570](https://github.com/strawberry-graphql/strawberry/pull/2570/) + + 0.216.1 - 2023-12-12 -------------------- diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index e0ea6a8355..0000000000 --- a/RELEASE.md +++ /dev/null @@ -1,53 +0,0 @@ -release type: minor - -Permissions classes now use a `FieldExtension`. The new preferred way to add permissions -is to use the `PermissionsExtension` class: - -```python -import strawberry -from strawberry.permission import PermissionExtension, BasePermission - - -class IsAuthorized(BasePermission): - message = "User is not authorized" - error_extensions = {"code": "UNAUTHORIZED"} - - def has_permission(self, source, info, **kwargs) -> bool: - return False - - -@strawberry.type -class Query: - @strawberry.field(extensions=[PermissionExtension(permissions=[IsAuthorized()])]) - def name(self) -> str: - return "ABC" -``` - -The old way of adding permissions using `permission_classes` is still -supported via the automatic addition of a `PermissionExtension` on the field. - -Using the new `PermissionExtension` API, permissions support even more features: - -#### Silent errors - -To return `None` or `[]` instead of raising an error, the `fail_silently ` keyword -argument on `PermissionExtension` can be set to `True`. - -#### Custom Error Extensions & classes - -Permissions will now automatically add pre-defined error extensions to the error, and -can use a custom `GraphQLError` class. This can be configured by modifying -the `error_class` and `error_extensions` attributes on the `BasePermission` class. - -#### Customizable Error Handling - -To customize the error handling, the `on_unauthorized` method on -the `BasePermission` class can be used. Further changes can be implemented by -subclassing the `PermissionExtension` class. - -#### Schema Directives - -Permissions will automatically be added as schema directives to the schema. This -behavior can be altered by setting the `add_directives` to `False` -on `PermissionExtension`, or by setting the `_schema_directive` class attribute of the -permission to a custom directive. diff --git a/pyproject.toml b/pyproject.toml index 2e60065aef..7bff61123f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "strawberry-graphql" packages = [ { include = "strawberry" } ] -version = "0.216.1" +version = "0.217.0" description = "A library for creating GraphQL APIs" authors = ["Patrick Arminio "] license = "MIT"