Skip to content

Commit

Permalink
chore(async): refactor, fix lint, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
suneet committed Nov 27, 2023
1 parent 213c7ba commit 0d82535
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def validate_email(email):
user = graphene.Field(AuthenticatedUser)

@classmethod
def mutate_and_get_payload(cls, root, info, **data):
cls.validate_email(data["email"])
user = user_services.get_and_authenticate_user(**data)
def mutate_and_get_payload(cls, root, info, email, password):
cls.validate_email(email)
user = user_services.get_and_authenticate_user(email, password)
return Login(user=user)


Expand All @@ -59,10 +59,8 @@ class Input:
user = graphene.Field(AuthenticatedUser)

@classmethod
def mutate_and_get_payload(cls, root, info, **data):
def mutate_and_get_payload(cls, root, info, current_password, new_password):
user = info.context.user
current_password = data["current_password"]
new_password = data["new_password"]

if not user.check_password(current_password):
raise GraphQLError("invalid_password")
Expand Down Expand Up @@ -93,8 +91,7 @@ def clean_user(cls, email):
return user

@classmethod
def mutate_and_get_payload(cls, root, info, **data):
email = data["email"]
def mutate_and_get_payload(cls, root, info, email):
user = cls.clean_user(email)

auth_services.send_password_reset_mail(user)
Expand All @@ -111,9 +108,7 @@ class Input:
message = graphene.String()

@classmethod
def mutate_and_get_payload(cls, root, info, **data):
new_password = data["new_password"]
token = data["token"]
def mutate_and_get_payload(cls, root, info, token, new_password):

user = tokens.get_user_for_password_reset_token(token)
password_validation.validate_password(new_password, user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import graphene
from graphene import relay
from graphene_django.filter import DjangoFilterConnectionField

from {{cookiecutter.main_module}}.graphql.decorators import login_required, superuser_required
from {{cookiecutter.main_module}}.graphql.utils import filter_objects
from {{cookiecutter.main_module}}.users.models import User

from .mutations import (
Login,
PasswordChange,
Expand All @@ -23,7 +23,7 @@ class UserQueries(graphene.ObjectType):
users = DjangoFilterConnectionField(
UserConnection, description="Return list of all Users"
)
user_details = relay.Node.Field(UserConnection)
user_details = graphene.Field(UserConnection, user_id=graphene.ID())

@login_required
def resolve_me(self, info):
Expand All @@ -36,9 +36,9 @@ def resolve_users(self, info, **kwargs):
return qs

@superuser_required
def resolve_user_details(self, info, **kwargs):
def resolve_user_details(self, info, user_id):
return filter_objects(
User, kwargs['id']
User, user_id
).first()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def filter_objects(object_name, relay_ids, otherwise=None):
relay_ids = [relay_ids]
try:
object_ids = [from_global_id(relay_id)[1] for relay_id in relay_ids]
return object_name.filter.with_ids(object_ids)
return object_name.objects.filter(id__in=object_ids)
except: # noqa
return otherwise

Expand Down

0 comments on commit 0d82535

Please sign in to comment.