Skip to content

Instantly share code, notes, and snippets.

@omarish
Created February 17, 2018 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarish/01d426f9b3ba9017356f315d4c4a3d3a to your computer and use it in GitHub Desktop.
Save omarish/01d426f9b3ba9017356f315d4c4a3d3a to your computer and use it in GitHub Desktop.
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