eamigo86 / graphene-django-extras

Extras functionalities for Graphene-Django
MIT License
417 stars 108 forks source link

Add support for custom resolvers. #176

Closed s3rius closed 3 years ago

s3rius commented 3 years ago

Description: This commit adds logic to use custom user resolvers instead of using only default manager queryset.

Signed-off-by: Pavel Kirilin win10@list.ru

s3rius commented 3 years ago

This pull request adds functionality that was requested in #34, #138 and #56.

Additionally you can now use django-graphql-jwt.

E.G.:

import graphene
from typing import Any
from graphql import GraphQLResolveInfo
from models import RandomModel
from types import RandomType
from graphene_django_extras import DjangoFilterPaginateListField
from graphql_jwt.decorators import login_required

class MyQuery(graphene.ObjectType):
    protected_list = DjangoFilterPaginateListField(RandomType)

    @staticmethod
    @login_required
    def resolve_protected_list(root: None, info: GraphQLResolveInfo, **_kwargs: Any):
        return RandomModel.objects.filter(user=info.context.user)