Я недавно начал изучать GraphQL. Я создал мутацию для пользовательской модели, и она работает нормально. Но когда я пытаюсь сделать то же самое для встроенной пользовательской модели Django. Я получаю ошибку. Не в состоянии решить это. Я пытаюсь создать нового пользователя, создав объект get_user_model через GraphQL.
class CreateUser(graphene.Mutation):
user = graphene.Field(UserType)
class Arguments:
username = graphene.String(required=True)
password = graphene.String(required=True)
email = graphene.String(request=True)
def mutate(self,info,username,password,email):
user = get_user_model(username=username,email=email)
user.set_password(password)
user.save()
return CreateUser(user=user)
class Mutation(graphene.ObjectType):
create_user = CreateUser.Field()
Получение вышеуказанной ошибки. Не уверен, в чем проблема. Пожалуйста, кто-нибудь объяснить.
Ошибка трассировки:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/graphql/
Django Version: 3.0.3
Python Version: 3.6.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'graphene_django',
'links']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/django/views/generic/base.py", line 62, in view
self = cls(**initkwargs)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene_django/views.py", line 79, in __init__
schema = graphene_settings.SCHEMA
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene_django/settings.py", line 117, in __getattr__
val = perform_import(val, attr)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene_django/settings.py", line 56, in perform_import
return import_from_string(val, setting_name)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene_django/settings.py", line 70, in import_from_string
module = importlib.import_module(module_path)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
<source code not available>
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
<source code not available>
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
<source code not available>
File "/Users/sunilhn/Documents/programming/django_fs/myDjangoProjects/graphqlhackernews/graphqlhackernews/schema.py", line 3, in <module>
import users.schema
File "/Users/sunilhn/Documents/programming/django_fs/myDjangoProjects/graphqlhackernews/users/schema.py", line 29, in <module>
class Mutation(graphene.ObjectType):
File "/Users/sunilhn/Documents/programming/django_fs/myDjangoProjects/graphqlhackernews/users/schema.py", line 30, in Mutation
create_user = CreateUser.Field()
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene/types/mutation.py", line 146, in Field
required=required,
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene/types/field.py", line 103, in __init__
self.args = to_arguments(args or OrderedDict(), extra_args)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene/types/argument.py", line 94, in to_arguments
arg = Argument.mounted(arg)
File "/Users/sunilhn/Documents/programming/Envs/graphenv/lib/python3.6/site-packages/graphene/types/mountedtype.py", line 19, in mounted
**unmounted.kwargs
Exception Type: TypeError at /graphql/
Exception Value: __init__() got an unexpected keyword argument 'request'