Skip to content

Instantly share code, notes, and snippets.

@neerajkumar161
Last active December 29, 2021 14:14
Show Gist options
  • Save neerajkumar161/062246df9bc4d5cb66af5d2f48c87e16 to your computer and use it in GitHub Desktop.
Save neerajkumar161/062246df9bc4d5cb66af5d2f48c87e16 to your computer and use it in GitHub Desktop.
/src/resolvers/create-user.ts
import {userModel} from '../models/user'
export const createUserResolver = async (parent: any, args: any, context: any) => {
let user = await userModel.find({email: args.email}).lean()
if (user.length) throw new Error('User already exists!')
user = await userModel.create(args)
if (!user) throw new Error('User creation failed')
return user
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment