doddy nicolas
10/01/2022, 11:52 AMprisma.ts
declare global {
var prisma: PrismaClient; // This must be a `var` and not a `let / const`
}
import { PrismaClient } from '@prisma/client'
let prisma: PrismaClient;
if(process.env.NODE_ENV === 'production'){
prisma = new PrismaClient();
}
else{
if(!global.prisma){
global.prisma = new PrismaClient();
}
prisma = global.prisma
}
export default prisma;
graphl.ts
import { createServer , createPubSub } from '@graphql-yoga/node'
import { User } from '@prisma/client'
import type { NextApiRequest, NextApiResponse } from 'next'
import prisma from '../../lib/prisma'
const schema = {schema: {
typeDefs: /* GraphQL */ `
type User {
lname: String
fname: String
}
type Mutation{
addUser(lname: String, fname: String): User!
}
`,
resolvers: {
Mutation: {
addUser: async(parent: any,_: any) => {
return await prisma.user.create(
data:{
lname:"coucou",
fname:"salut"
}
)}
},
}
}
i just want to add a new user in graphql with prisma but the resolver don't work <https://github.com/doddynicolas/try-prisma.git>
Jarupong
10/01/2022, 11:54 AMJarupong
10/01/2022, 11:55 AMVladi Stevanovic