33 lines
750 B
Python
33 lines
750 B
Python
import strawberry
|
|
import strawberry_django
|
|
from django.contrib.auth import get_user_model
|
|
from django.db import transaction
|
|
from strawberry_django import auto
|
|
|
|
from main import models
|
|
from main.api.types.users import User
|
|
|
|
DjangoUser = get_user_model()
|
|
|
|
|
|
@strawberry_django.input(DjangoUser)
|
|
class UserInput:
|
|
email: auto
|
|
first_name: auto
|
|
last_name: auto
|
|
|
|
|
|
@strawberry.mutation
|
|
@transaction.atomic
|
|
def register_mutation(input: UserInput) -> User:
|
|
user = DjangoUser.objects.create_user(
|
|
first_name=input.first_name, last_name=input.last_name, email=input.email, username=input.email
|
|
)
|
|
models.UserProfile.objects.create(user=user)
|
|
return user
|
|
|
|
|
|
@strawberry.type
|
|
class UsersMutations:
|
|
register = register_mutation
|