Fakultas Ilmu Komputer UI

query.py 801 Bytes
Newer Older
1
2
3
4
5
6
7
8
import graphene
from django.db.models import Q

from .models import Mustahik
from .types import MustahikType

class MustahikQuery(graphene.ObjectType):
    mustahiks = graphene.List(MustahikType, statuses=graphene.List(graphene.String))
9
    mustahik = graphene.Field(MustahikType, id=graphene.ID())
10
11
12
13
14
15
16
17
18

    def resolve_mustahiks(self, info, statuses=[], **kwargs):
        if statuses and len(statuses) > 0:
            filter = Q(status=statuses[0])
            for status in statuses:
                filter = filter | Q(status=status)
            return Mustahik.objects.filter(filter)

        return Mustahik.objects.all()
19

20
21
22
23
24
    def resolve_mustahik(self, info, id):
        mustahik = Mustahik.objects.get(pk=id)
        if mustahik is not None:
            return mustahik