Last active
December 29, 2021 14:14
-
-
Save neerajkumar161/062246df9bc4d5cb66af5d2f48c87e16 to your computer and use it in GitHub Desktop.
/src/resolvers/create-user.ts
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 {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