Initial working API #69

Merged
lukas merged 7 commits from add-api into main 2023-11-30 16:38:27 +00:00
1 changed files with 26 additions and 1 deletions
Showing only changes of commit 52513e1ed8 - Show all commits

View File

@ -15,6 +15,27 @@ class Game(DjangoObjectType):
fields = "__all__" 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 Edition(DjangoObjectType):
class Meta: class Meta:
model = EditionModel model = EditionModel
@ -79,4 +100,8 @@ class Query(graphene.ObjectType):
return DeviceModel.objects.all() return DeviceModel.objects.all()
schema = graphene.Schema(query=Query) class Mutation(graphene.ObjectType):
update_game = UpdateGameMutation.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)