From e9e61403a9f3c93f02bf1c3ffd86a40c68954c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 29 Nov 2023 21:05:34 +0100 Subject: [PATCH] Add UpdateGameMutation --- api/schema.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/api/schema.py b/api/schema.py index 98f3860..c359e08 100644 --- a/api/schema.py +++ b/api/schema.py @@ -15,6 +15,27 @@ class Game(DjangoObjectType): fields = "__all__" +class UpdateGameMutation(graphene.Mutation): + class Arguments: + id = graphene.ID(required=True) + name = graphene.String() + year_released = graphene.Int() + wikidata = graphene.String() + + game = graphene.Field(Game) + + def mutate(self, info, id, name=None, year_released=None, wikidata=None): + game_instance = GameModel.objects.get(pk=id) + if name is not None: + game_instance.name = name + if year_released is not None: + game_instance.year_released = year_released + if wikidata is not None: + game_instance.wikidata = wikidata + game_instance.save() + return UpdateGameMutation(game=game_instance) + + class Edition(DjangoObjectType): class Meta: model = EditionModel @@ -79,4 +100,8 @@ class Query(graphene.ObjectType): return DeviceModel.objects.all() -schema = graphene.Schema(query=Query) +class Mutation(graphene.ObjectType): + update_game = UpdateGameMutation.Field() + + +schema = graphene.Schema(query=Query, mutation=Mutation)