Would be quite useful, IMO.
I would prefer to have an option to return some value in a restricted fields in case of a permission fail.
Possible solution:
A new permission base class
class QuietBasePermission(BasePermission):
default_value: Any = None
And some changes in GraphQLCoreConverter to handle it:
async def _check_permissions_async(
source: Any, info: Info, kwargs: Dict[str, Any]
) -> Optional[QuietBasePermission]:
failed_perm = None
for permission_class in field.permission_classes:
permission = permission_class()
has_permission: bool
has_permission = await await_maybe(
permission.has_permission(source, info, **kwargs)
)
if not has_permission and not isinstance(permission, QuietBasePermission):
message = getattr(permission, "message", None)
raise PermissionError(message)
elif not has_permission:
failed_perm = permission
return failed_perm
....
async def _async_resolver(_source: Any, info: GraphQLResolveInfo, **kwargs):
strawberry_info = _strawberry_info_from_graphql(info)
perm_failed = await _check_permissions_async(_source, strawberry_info, kwargs)
if perm_failed:
return perm_failed.default_value
return await await_maybe(_get_result(_source, strawberry_info, **kwargs))
It returns the last default value for a permission check fail if there are multiple, and raises a PermissionError if required by some other permission.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too