File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,31 @@ conversely you can use ``exclude`` meta attribute.
48
48
exclude = (' published' , ' owner' )
49
49
interfaces = (relay.Node, )
50
50
51
+
52
+ Another pattern is to have a resolve method act as a gatekeeper, returning None
53
+ or raising an exception if the client isn't allowed to see the data.
54
+
55
+ .. code :: python
56
+
57
+ from graphene import relay
58
+ from graphene_django.types import DjangoObjectType
59
+ from .models import Post
60
+
61
+ class PostNode (DjangoObjectType ):
62
+ class Meta :
63
+ model = Post
64
+ fields = (' title' , ' content' , ' owner' )
65
+ interfaces = (relay.Node, )
66
+
67
+ def resolve_owner (self , info ):
68
+ user = info.context.user
69
+ if user.is_anonymous:
70
+ raise PermissionDenied(" Please login" )
71
+ if not user.is_staff:
72
+ return None
73
+ return self .owner
74
+
75
+
51
76
Queryset Filtering On Lists
52
77
---------------------------
53
78
You can’t perform that action at this time.
0 commit comments