PermissionExtension
Handles permissions for a field.
Instantiate this as a field extension with all of the permissions you want to apply.
Note: Currently, this is automatically added to the field, when using field.permission_classes
This is deprecated behaviour, please manually add the extension to field.extensions
Constructor:
Initialize the permission extension.
Signature:
def __init__( self, permissions: List[BasePermission], use_directives: bool = True, fail_silently: bool = False,) -> None: ...Parameters:
-
permissions:List of permissions to apply.
- Type
-
List[BasePermission]
-
use_directives:If True, add schema directives to the field.
- Type
-
bool - Default
-
True
-
fail_silently:If True, return None or [] instead of raising an exception. This is only valid for optional or list fields.
- Type
-
bool - Default
-
False
Methods:
-
apply
Applies all of the permission directives to the schema and sets up silent permissions.
Signature:
def apply(self, field: StrawberryField) -> None:...Parameters:
-
field:- Type
-
StrawberryField
-
-
resolve
Checks if the permission should be accepted and raises an exception if not.
Signature:
def resolve(self,next_: SyncExtensionResolver,source: Any,info: Info,kwargs: Dict[str, Any] = {},) -> Any:...Parameters:
-
next_:- Type
-
SyncExtensionResolver
-
source:- Type
-
Any
-
info:- Type
-
Info
-
kwargs:- Type
-
Dict[str, Any] - Default
-
{}
-
-
resolve_async
Signature:
def resolve_async(self,next_: AsyncExtensionResolver,source: Any,info: Info,kwargs: Dict[str, Any] = {},) -> Any:...Parameters:
-
next_:- Type
-
AsyncExtensionResolver
-
source:- Type
-
Any
-
info:- Type
-
Info
-
kwargs:- Type
-
Dict[str, Any] - Default
-
{}
-
Attributes:
-
permissions: -
fail_silently: -
return_empty_list: -
use_directives: -
supports_sync:Whether this extension can be resolved synchronously or not.
The Permission extension always supports async checking using await_maybe, but only supports sync checking if there are no async permissions.
- Type
-
bool