Created
February 17, 2018 23:42
-
-
Save omarish/01d426f9b3ba9017356f315d4c4a3d3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mutations | |
class UserSignup(mutations.Mutation): | |
"""Sign up the user if and only if their name is a palindrome. """ | |
name = mutations.fields.CharField() | |
email = mutations.fields.CharField() | |
def validate_name_is_palindrome(self): | |
""" | |
Since this method is prefixed with validate_, it's assumed to be | |
a validator and will be run before the command is executed. | |
Validators should either return None (if the validator passes), or | |
raise ValidationError with an error message if there is a problem. | |
""" | |
if not is_palindrome(self.name): | |
raise mutations.error.ValidationError(f"{self.name} is not a Palindrome!") | |
def execute(self): | |
""" | |
This only gets called if the user's name is a palindrome. | |
""" | |
user = User.objects.create([...]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment