(doc, auth): also show that one can raise an exception in a resolve method

This commit is contained in:
Jason Kraus 2021-01-29 16:38:49 -08:00
parent 93ec8eb099
commit 712d99caa4

View File

@ -50,7 +50,7 @@ conversely you can use ``exclude`` meta attribute.
Another pattern is to have a resolve method act as a gatekeeper, returning None Another pattern is to have a resolve method act as a gatekeeper, returning None
if the client isn't allowed to see the data. or raising an exception if the client isn't allowed to see the data.
.. code:: python .. code:: python
@ -65,7 +65,10 @@ if the client isn't allowed to see the data.
interfaces = (relay.Node, ) interfaces = (relay.Node, )
def resolve_owner(self, info): def resolve_owner(self, info):
if info.context.user.is_anonymous(): user = info.context.user
if user.is_anonymous:
raise PermissionDenied("Please login")
if not user.is_staff:
return None return None
return self.owner return self.owner