|
| 1 | +import graphene |
| 2 | + |
| 3 | +from ..type import ExpectedErrorType |
| 4 | + |
| 5 | +# TODO: if for custom was here |
| 6 | +OutputErrorType = ExpectedErrorType |
| 7 | + |
| 8 | + |
| 9 | +class BaseAuthMutation(graphene.Mutation): |
| 10 | + success = graphene.Boolean(default_value=True) |
| 11 | + errors = graphene.Field(OutputErrorType) |
| 12 | + |
| 13 | + class Meta: |
| 14 | + abstract = True |
| 15 | + |
| 16 | + @classmethod |
| 17 | + def mutate(cls, root, info, **data): |
| 18 | + return cls.perform_mutation(root, info, **data) |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def perform_mutation(cls, root, info, **data): |
| 22 | + pass |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def success_response(cls): |
| 26 | + """Return a success response.""" |
| 27 | + return cls(**{"errors": []}) |
| 28 | + |
| 29 | + @classmethod |
| 30 | + def unsuccess_response(cls): |
| 31 | + """Return a success response.""" |
| 32 | + return cls(**{"errors": ["That did not go Well"]}) |
| 33 | + |
| 34 | + |
| 35 | +class BaseRegister(BaseAuthMutation): |
| 36 | + |
| 37 | + """ |
| 38 | + # how do I pass the arguments to the mutation as it is |
| 39 | + # without defining and input variable so that the mutation |
| 40 | + # can be called like this: |
| 41 | + register( |
| 42 | + email: String! |
| 43 | + username: String! |
| 44 | + password1: String! |
| 45 | + password2: String! |
| 46 | + ): Register |
| 47 | + """ |
| 48 | + |
| 49 | + class Arguments: |
| 50 | + email = graphene.String(required=True, description="Email") |
| 51 | + username = graphene.String(required=True, description="Username") |
| 52 | + password = graphene.String(required=True, description="Password") |
| 53 | + |
| 54 | + class Meta: |
| 55 | + abstract = True |
| 56 | + |
| 57 | + |
| 58 | +class VerifyAccountBase(BaseAuthMutation): |
| 59 | + class Arguments: |
| 60 | + token = graphene.String(required=True, description="Token") |
| 61 | + |
| 62 | + class Meta: |
| 63 | + abstract = True |
| 64 | + |
| 65 | + |
| 66 | +class ResendActivationEmailBase(BaseAuthMutation): |
| 67 | + class Arguments: |
| 68 | + email = graphene.String(required=True, description="Email") |
| 69 | + |
| 70 | + class Meta: |
| 71 | + abstract = True |
| 72 | + |
| 73 | + |
| 74 | +class SendPasswordResetEmailBase(BaseAuthMutation): |
| 75 | + class Arguments: |
| 76 | + email = graphene.String(required=True, description="Email") |
| 77 | + |
| 78 | + class Meta: |
| 79 | + abstract = True |
| 80 | + |
| 81 | + |
| 82 | +class PasswordResetBase(BaseAuthMutation): |
| 83 | + class Arguments: |
| 84 | + token = graphene.String(required=True, description="Token") |
| 85 | + newPassword = graphene.String(required=True, description="NewPassword") |
| 86 | + |
| 87 | + class Meta: |
| 88 | + abstract = True |
| 89 | + |
| 90 | + |
| 91 | +class PasswordSetBase(BaseAuthMutation): |
| 92 | + class Arguments: |
| 93 | + token = graphene.String(required=True, description="Token") |
| 94 | + newPassword = graphene.String(required=True, description="NewPassword") |
| 95 | + |
| 96 | + class Meta: |
| 97 | + abstract = True |
0 commit comments