From a461953141985583a403d5e591e59780f82bcf07 Mon Sep 17 00:00:00 2001 From: C Chan Date: Mon, 7 Nov 2022 02:11:31 -0800 Subject: [PATCH] Specify fields for return in mutation Added field specifications for mutations to prevent this type of error: `TypeError: _init_() takes 1 positional argument but 4 were given` --- strawberry-gql/app/schema.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/strawberry-gql/app/schema.py b/strawberry-gql/app/schema.py index c5c31fb..5aec920 100644 --- a/strawberry-gql/app/schema.py +++ b/strawberry-gql/app/schema.py @@ -95,7 +95,7 @@ async def create_actor( ) actor = json.loads(actor_json) - return Actor(actor.get("name"), actor.get("age"), actor.get("height")) + return Actor(name=actor.get("name"), age=actor.get("age"), height=actor.get("height")) @strawberry.mutation async def update_actors( @@ -184,7 +184,7 @@ async def create_movie( movie = json.loads(movie_json) actors = [Actor(name) for d in movie.get("actors", []) for name in d.values()] - return Movie(movie.get("name"), movie.get("year"), actors) + return Movie(name=movie.get("name"), year=movie.get("year"), actors=actors) @strawberry.mutation async def update_movies( @@ -227,7 +227,7 @@ async def update_movies( Actor(d.get("name"), d.get("age"), d.get("height")) for d in movie.get("actors", []) ] - movies[idx] = Movie(movie.get("name"), movie.get("year"), actors) + movies[idx] = Movie(name=movie.get("name"), year=movie.get("year"), actors=actors) return movies @strawberry.mutation @@ -249,7 +249,7 @@ async def delete_movies(self, filter_name: str) -> list[Movie]: Actor(d.get("name"), d.get("age"), d.get("height")) for d in movie.get("actors", []) ] - movies[idx] = Movie(movie.get("name"), movie.get("year"), actors) + movies[idx] = Movie(name=movie.get("name"), year=movie.get("year"), actors=actors) return movies