Fakultas Ilmu Komputer UI

Commit db50eef5 authored by Ilma Ainur Rohma's avatar Ilma Ainur Rohma
Browse files

[GREEN] add read detail query and delete mutation

parent 549622a5
......@@ -32,4 +32,15 @@ class MustahikMutation(DjangoModelFormMutation):
mustahik = graphene.Field(MustahikType)
class Meta:
form_class = MustahikForm
\ No newline at end of file
form_class = MustahikForm
class DeleteMustahik(graphene.Mutation):
class Arguments:
id = graphene.ID()
mustahik = graphene.Field(MustahikType)
def mutate(self, info, id):
mustahik = Mustahik.objects.get(pk=id)
if mustahik is not None:
mustahik.delete()
......@@ -6,6 +6,7 @@ from .types import MustahikType
class MustahikQuery(graphene.ObjectType):
mustahiks = graphene.List(MustahikType, statuses=graphene.List(graphene.String))
mustahik = graphene.Field(MustahikType, id=graphene.ID())
def resolve_mustahiks(self, info, statuses=[], **kwargs):
if statuses and len(statuses) > 0:
......@@ -16,3 +17,8 @@ class MustahikQuery(graphene.ObjectType):
return Mustahik.objects.all()
def resolve_mustahik(self, info, id):
mustahik = Mustahik.objects.get(pk=id)
if mustahik is not None:
return mustahik
......@@ -279,6 +279,8 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
op_name='detailMustahikQuery',
variables={'id':mustahik_id}
)
self.assertResponseNoErrors(response)
content = json.loads(response.content)
self.assertEqual(len(content['data']), 1)
self.assertEqual(content['data']['mustahik']['name'], 'mustahik')
......
......@@ -2,7 +2,7 @@ import graphene
from graphene_django import DjangoObjectType
from .mustahik.mutations import MustahikMutation
from .mustahik.mutations import MustahikMutation, DeleteMustahik
from .mustahik.query import MustahikQuery
ABOUT = 'Si Zakat merupakan sistem informasi untuk membantu masjid dalam \
......@@ -19,6 +19,7 @@ class Query(MustahikQuery, graphene.ObjectType):
class Mutation(graphene.ObjectType):
mustahik_mutation = MustahikMutation.Field()
delete_mustahik = DeleteMustahik.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment