Open ash-lyrid opened 7 months ago
I think there is no straight forward way to add the email type to the user type as I am using a custom email field. I can see there is a TODO item to support custom UserType implementation. I will wait till that is implemented as I am unable to use this package for the time being. Please correct me if there is an alternative way to resolve this. Thanks.
what's your email_field
?
from gqlauth.settings_type import GqlAuthSettings, password_field, email_field
I am using email_field
from gqlauth
only
This is my custom email field.
class LowercaseEmailField(models.EmailField):
"""
Override EmailField to convert emails to lowercase before saving.
"""
def to_python(self, value):
"""
Convert email to lowercase.
"""
value = super(LowercaseEmailField, self).to_python(value)
# Value can be None so check that it's a string before lowercasing.
if isinstance(value, str):
return value.lower()
return value
Can you show your GQLAUTH_SETTINGS
? including the implementations of email_field
etc
and a full stacktrace
GQL_AUTH = GqlAuthSettings(
LOGIN_REQUIRE_CAPTCHA=False,
REGISTER_REQUIRE_CAPTCHA=False,
ALLOW_LOGIN_NOT_VERIFIED=True,
LOGIN_FIELDS={email_field, password_field},
REGISTER_MUTATION_FIELDS={email_field},
# CAPTCHA_EXPIRATION_DELTA=timedelta(seconds=120),
# CAPTCHA_MAX_RETRIES=5,
# CAPTCHA_TEXT_FACTORY=default_text_factory,
# CAPTCHA_TEXT_VALIDATOR=default_captcha_text_validator,
# FORCE_SHOW_CAPTCHA=False,
# CAPTCHA_SAVE_IMAGE=False,
UPDATE_MUTATION_FIELDS={email_field},
JWT_PAYLOAD_PK=email_field,
)
Traceback (most recent call last):
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/graphql/type/definition.py", line 808, in fields
fields = resolve_thunk(self._fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/graphql/type/definition.py", line 300, in resolve_thunk
return thunk() if callable(thunk) else thunk
^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 525, in <lambda>
fields=lambda: self.get_graphql_fields(object_type),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 382, in get_graphql_fields
return _get_thunk_mapping(
^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 129, in _get_thunk_mapping
field_type = field.type
^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/strawberry/field.py", line 302, in type
return self.resolve_type()
^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/strawberry_django/fields/base.py", line 184, in resolve_type
resolved_type = resolve_model_field_type(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/strawberry_django/fields/types.py", line 508, in resolve_model_field_type
raise NotImplementedError(
NotImplementedError: GraphQL type for model field 'users.User.email' has not been implemented
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/ashish/Projects/Lyrid/FreeI/manage.py", line 24, in <module>
main()
File "/Users/ashish/Projects/Lyrid/FreeI/manage.py", line 19, in main
execute_from_command_line(sys.argv)
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 88, in execute
return super().execute(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/management/base.py", line 453, in execute
self.check()
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/management/base.py", line 485, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/core/checks/urls.py", line 24, in check_resolver
return check_method()
^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/urls/resolvers.py", line 494, in check
for pattern in self.url_patterns:
^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/urls/resolvers.py", line 715, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
return import_module(self.urlconf_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/ashish/Projects/Lyrid/FreeI/config/urls.py", line 6, in <module>
from .schema import schema
File "/Users/ashish/Projects/Lyrid/FreeI/config/schema.py", line 64, in <module>
schema = JwtSchema(
^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/strawberry/schema/schema.py", line 143, in __init__
self._schema = GraphQLSchema(
^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/graphql/type/schema.py", line 224, in __init__
collect_referenced_types(query)
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/graphql/type/schema.py", line 433, in collect_referenced_types
collect_referenced_types(field.type)
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/graphql/type/schema.py", line 432, in collect_referenced_types
for field in named_type.fields.values():
^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/functools.py", line 1001, in __get__
val = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/Users/ashish/Env/FreeI/lib/python3.11/site-packages/graphql/type/definition.py", line 811, in fields
raise cls(f"{self.name} fields cannot be resolved. {error}") from error
TypeError: UserType fields cannot be resolved. GraphQL type for model field 'users.User.email' has not been implemented
Dude where do you get email_field
from ?
Using the following.
from gqlauth.settings_type import GqlAuthSettings, password_field, email_field
I see, thats weird. could you create a reproducible example?
I am trying to use this package, coming from django graphene auth background.
I am getting the following error -
TypeError: UserType fields cannot be resolved. GraphQL type for model field 'users.User.email' has not been implemented
GqlAuthSettings
CustomUserModel
schema.py