Bump strawberry-graphql[fastapi] from 0.216.1 to 0.217.0
Bumps strawberry-graphql[fastapi] from 0.216.1 to 0.217.0.
Release notes
Sourced from strawberry-graphql[fastapi]'s releases.
🍓 0.217.0Permissions classes now use a
FieldExtension
. The new preferred way to add permissions is to use thePermissionsExtension
class: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 aPermissionExtension
on the field.Using the new
PermissionExtension
API, permissions support even more features:Silent errors
To return
None
or[]
instead of raising an error, thefail_silently
keyword argument onPermissionExtension
can be set toTrue
.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 theerror_class
anderror_extensions
attributes on theBasePermission
class.Customizable Error Handling
To customize the error handling, the
on_unauthorized
method on theBasePermission
class can be used. Further changes can be implemented by subclassing thePermissionExtension
class.Schema Directives
Permissions will automatically be added as schema directives to the schema. This behavior can be altered by setting the
add_directives
toFalse
... (truncated)
Changelog
Sourced from strawberry-graphql[fastapi]'s changelog.
0.217.0 - 2023-12-18
Permissions classes now use a
FieldExtension
. The new preferred way to add permissions is to use thePermissionsExtension
class: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 aPermissionExtension
on the field.Using the new
PermissionExtension
API, permissions support even more features:Silent errors
To return
None
or[]
instead of raising an error, thefail_silently
keyword argument onPermissionExtension
can be set toTrue
.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 theerror_class
anderror_extensions
attributes on theBasePermission
class.Customizable Error Handling
To customize the error handling, the
on_unauthorized
method on theBasePermission
class can be used. Further changes can be implemented by subclassing thePermissionExtension
class.Schema Directives
... (truncated)
Commits
-
528b1b3
Release🍓 0.217.0 -
599e3a3
refactor: Permissions using Field Extensions (#2570) - See full diff in compare view