import { gql } from 'apollo-server'
export default gql`
type CreateAccountResult {
ok: Boolean!
error: String
}
type Mutation {
createAccount(
username: String!
email: String!
password: String!
): CreateAccountResult!
}
`
import prisma from '../../client'
import bcrypt from 'bcryptjs'
export default {
Mutation: {
createAccount: async (_, { username, email, password }) => {
try {
const existingUser = await prisma.user.findFirst({
where: { OR: [{ username }, { email }] },
})
if (existingUser) {
throw new Error('This username/password is already taken.')
}
const uglyPassword = await bcrypt.hash(password, 10)
await prisma.user.create({
data: {
username,
email,
password: uglyPassword,
},
})
return {
ok: true,
}
} catch (e) {
return e
}
},
},
}
보고또보고 실습하고 또실습하자
나는 머리가 그닥이라~