I have added an additional argument called user_type
to disposal_request
query, and I want to use this argument to add another filter but when I passed it to get_queryset
function. I get the following error: get_queryset() missing 1 required positional argument: 'user_type'
I'm not sure how to pass the argument properly.
import graphene
import graphene_django
from app.disposer.models import DisposalRequest
from graphene_django.filter import DjangoFilterConnectionField
from graphql_jwt.decorators import login_required
class UserType(graphene.Enum):
as_collector = "as_collector"
as_disposer = "as_disposer"
class DisposalRequestsType(graphene_django.DjangoObjectType):
latitude = graphene.String()
longitude = graphene.String()
class Meta:
model = DisposalRequest
exclude = ("location",)
filter_fields = [
"uuid",
"disposal_status",
]
interfaces = (graphene.Node,)
convert_choices_to_enum = False
@classmethod
@login_required
def get_queryset(cls, queryset, info, user_type):
user = info.context.user
if user_type == UserType.as_collector:
print("as_collector")
return queryset.filter(collector=user)
elif user_type == UserType.as_disposer:
print("as_disposer")
return queryset.filter(disposer=user)
def resolve_latitude(self, _):
return self.location.x
def resolve_longitude(self, _):
return self.location.y
class DisposalQueries(graphene.ObjectType):
disposal_requests = DjangoFilterConnectionField(
DisposalRequestsType, user_type=UserType()
)
I ended up putting the additional filter to
resolve_
function and pass **kwargs for additional fields added byDjangoFilterConnectionField