Skip to content

Instantly share code, notes, and snippets.

@clarencenpy
Last active July 5, 2018 17:52
Show Gist options
  • Save clarencenpy/a6579666c3df9188a41d175039e12319 to your computer and use it in GitHub Desktop.
Save clarencenpy/a6579666c3df9188a41d175039e12319 to your computer and use it in GitHub Desktop.
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