mentorenwahl/docker/backend_old/src/schema/mutation.ts
2022-01-08 13:29:22 +01:00

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,
},
});
},
});
},
});