Last active
July 5, 2018 17:52
-
-
Save clarencenpy/a6579666c3df9188a41d175039e12319 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 { UserInputError } from 'apollo-server'; | |
const resolvers = { | |
Query: { | |
events(root, { zipCode }) { | |
// do custom validation for user inputs | |
const validationErrors = {}; | |
if (!isValidZipCode(zipCode)) { | |
validationErrors.zipCode = 'This is not a valid zipcode'; | |
} | |
if (Object.keys(validationErrors).length > 0) { | |
throw new UserInputError( | |
'Failed to get events due to validation errors', | |
{ validationErrors } | |
); | |
} | |
// actually query events here and return successfully | |
return getEventsByZipcode(zipCode); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment