django-graphene-permissions
django-graphene-permissions copied to clipboard
Work without relay.Node interfaces
Can this package work without relay.Node interfaces? Checking for permissions happens in get_node func, but if used without relay, this func never gets called.
You can, but you need to use the permissions_checker
decorator on the object resolver
class Query(graphene.ObjectType):
category = graphene.Field(CategoryType, id=graphene.Int())
categories = graphene.List(CategoryType)
@permissions_checker([IsAuthenticated])
def resolve_category(self, info, **kwargs):
id = kwargs.get('id')
return Category.objects.get(pk=id)
@permissions_checker([IsAuthenticated])
def resolve_categories(self, info, **kwargs):
return Category.objects.all()
Oh yeah, I saw that in docs, but it can be more convenient to use it without decorating every resolver, something like that:
class CategoryType(PermissionDjangoObjectType):
class Meta:
model = Category
@staticmethod
def permission_classes():
return [IsAuthenticated]
class Query(graphene.ObjectType):
category = graphene.Field(CategoryType, id=graphene.Int())
def resolve_category(self, info, **kwargs):
# etc
This affects how default_resolver is evaluating and will require some additional work on PermissionDjangoObjectType or even another subclass for queries. You can consider it a feature request =)
I will work on it when I got some free time, Thanks :)