Improve mutation test

This commit is contained in:
Jonathan Kim 2020-06-27 18:15:35 +01:00
parent efe77998d4
commit e42a826078

View File

@ -179,30 +179,25 @@ def test_mutation_complex_input():
name = String(required=True) name = String(required=True)
email = String(required=True) email = String(required=True)
class CreateUserSuccess(ObjectType): MUTATION_PREFIX = "CreateUser"
class Success(ObjectType, type_name=f"{MUTATION_PREFIX}Success"):
user = Field(User, required=True) user = Field(User, required=True)
class CreateUserError(ObjectType): class Error(ObjectType, type_name=f"{MUTATION_PREFIX}Error"):
error_message = String(required=True) error_message = String(required=True)
class CreateUserOutput(Union): class Input(InputObjectType, type_name=f"{MUTATION_PREFIX}Input"):
class Meta:
types = [
CreateUserSuccess,
CreateUserError,
]
class CreateUserInput(InputObjectType):
name = String(required=True) name = String(required=True)
email = String(required=True) email = String(required=True)
@mutation( @mutation(
CreateUserOutput, Union.create_type(f"{MUTATION_PREFIX}Output", types=[Success, Error]),
required=True, required=True,
arguments={"user": CreateUserInput(required=True)}, arguments={"user": Input(required=True)},
) )
def create_user(root, info, user): def create_user(root, info, user):
return CreateUserSuccess(user=User(**user)) return Success(user=User(**user))
class Query(ObjectType): class Query(ObjectType):
a = String() a = String()