28 lines
744 B
TypeScript
28 lines
744 B
TypeScript
import { mutationType, arg, nonNull } from "nexus";
|
|
import * as argon2 from "argon2";
|
|
|
|
import { Context } from "../context";
|
|
import { User, UserCreateInput } from "./user";
|
|
|
|
export const Mutation = mutationType({
|
|
definition(t) {
|
|
t.nonNull.field("createUser", {
|
|
type: User,
|
|
args: {
|
|
input: nonNull(arg({ type: UserCreateInput })),
|
|
},
|
|
async resolve(_root, args, ctx: Context) {
|
|
return ctx.prisma.user.create({
|
|
data: {
|
|
firstname: args.input.firstname,
|
|
lastname: args.input.lastname,
|
|
email: args.input.email,
|
|
password: await argon2.hash(args.input.password),
|
|
role: args.input.role,
|
|
},
|
|
});
|
|
},
|
|
});
|
|
},
|
|
});
|