Skip to content

Commit

Permalink
[ADD] add optional field
Browse files Browse the repository at this point in the history
  • Loading branch information
Elise17 committed Mar 15, 2024
1 parent 84aa5d4 commit 13a24c9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions experiments/graphql-rest/POC-Graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,23 @@ def mutate(self, info, title, description, year, username):
class UpdateBook(graphene.Mutation):
"""Mutation Updatebook """
class Arguments:
title = graphene.String(required=True)
description = graphene.String(required=True)
year = graphene.Int(required=True)
author_id= graphene.Int(required=False)
title = graphene.String(required=False, default_value=None)
description = graphene.String(required=False, default_value=None)
year = graphene.Int(required=False, default_value=None)
author_id = graphene.Int(required=False, default_value=None)
book = graphene.Field(lambda: BookObject)

def mutate(self, info, title, description, year, author_id):

book_instance = Book.query.filter_by(title=title).first()

if book_instance:
book_instance.description = description
book_instance.year = year
book_instance.author_id = author_id
if description:
book_instance.description = description
if year:
book_instance.year = year
if author_id:
book_instance.author_id = author_id
db.session.commit()
return UpdateBook(book=book_instance)
return UpdateBook(book=None)
Expand Down

0 comments on commit 13a24c9

Please sign in to comment.