Last active
August 17, 2018 12:35
-
-
Save aswinmprabhu/6b3902ed6193cefcd4f0c9c3902d7c3b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const makeCustomResolver = (userSchema) => { | |
// Create custom resolvers | |
const customResolver = { | |
Mutation: { | |
insert_user(parent, args, context, info){ | |
let newArgs = { objects:[] }; | |
// Convert the email to lower case and append each object to the new arguments array | |
for (const user of args.objects) { | |
user.email = user.email.toLowerCase(); | |
newArgs.objects.push(user); | |
} | |
// Delegate after sanitization | |
return info.mergeInfo.delegateToSchema({ | |
schema: userSchema, | |
operation: 'mutation', | |
fieldName: 'insert_user', | |
args: newArgs, | |
context, | |
info, | |
}); | |
} | |
} | |
}; | |
return customResolver; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment