-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
const bcrypt = require('bcryptjs'); | ||
|
||
const User = require('../models/user'); | ||
|
||
/** | ||
* All ROOT RESOLVERS RECEIVE (args, context, info) ARGS | ||
* NOTE CONFIGURATION IN app.js INJECTING req,res INTO context ARG | ||
*/ | ||
module.exports = { | ||
hello() { | ||
return { | ||
text: 'Hello World!', | ||
views: 1, | ||
}; | ||
createUser: async ({ userInput }, _context, _info) => { | ||
// const email = source.userInput.email; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
const existingUser = await User.findOne({ email: userInput.email }); | ||
if (existingUser) { | ||
const error = new Error('User exists already!'); | ||
throw error; | ||
} | ||
|
||
const hashPw = await bcrypt.hash(userInput.password, 12); | ||
const user = new User({ | ||
email: userInput.email, | ||
name: userInput.name, | ||
password: hashPw, | ||
}); | ||
const createdUser = await user.save(); | ||
return { ...createdUser._doc, _id: createdUser._id.toString() }; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}, | ||
}; |
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
不用解構的話 代表的是 args 你傳的物件 在前面的schema 定義中它是 一個 userInput,我們再拿取此type 的 email 。