Sascha
09/07/2020, 7:31 AMRyan
09/07/2020, 7:38 AMSascha
09/07/2020, 7:40 AMSascha
09/07/2020, 7:40 AMRyan
09/07/2020, 7:42 AMconst prisma = new PrismaClient()
prisma.$use(async (params, next) => {
console.log('middlware called')
const result = next(params)
return result
})
const nexusPrisma = nexusSchemaPrisma({
experimentalCRUD: true,
prismaClient: (ctx: Context) => ctx.prisma,
})
const server = new ApolloServer({
schema,
context: createContext, // pass the instance of Prisma Client here
playground: true,
})
This will work when you call the middlewareSascha
09/07/2020, 7:42 AMSascha
09/07/2020, 7:43 AMRyan
09/07/2020, 7:44 AMimport { use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'
import { PrismaClient } from 'nexus-plugin-prisma/client'
use(
prisma({
client: {
instance: client,
},
})
)
Sascha
09/07/2020, 7:49 AMSascha
09/07/2020, 7:51 AMSascha
09/07/2020, 11:35 AM✕ nexus reflection failed
| error Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
| In case this error is unexpected for you, please report it in <https://github.com/prisma/prisma-client-js/issues/390>.
✕ nexus reflection failed
| error Error: @prisma/client did not initirun for documentation about this command.
Sascha
09/07/2020, 11:36 AMSascha
09/07/2020, 11:36 AM"dependencies": {
"nexus": "^0.26.1",
"nexus-plugin-auth0": "^0.1.1",
"nexus-plugin-prisma": "^0.18.1",
"nexus-plugin-shield": "^0.2.0",
"typescript": "^3.7.5"
},
Sascha
09/07/2020, 11:37 AMRyan
09/07/2020, 11:47 AMnexus-plugin-prisma
. Could you try restarting the server and check?
const client = new PrismaClient({
log: isDev() ? ['query'] : [],
})
use(
prisma({
client: {
instance: client,
},
features: {
crud: true,
},
})
)
client.$use(async (params, next) => {
console.log('called', params)
const result = next(params)
return result
})
The above code-snippet is working for meSascha
09/07/2020, 11:51 AMRyan
09/07/2020, 11:56 AMprisma generate
separately before running Nexus. If that still doesn’t work, then it’s best if you could provide a reproduction repo so that I can check.Sascha
09/07/2020, 12:06 PMschema.prisma
by any chance?Sascha
09/07/2020, 12:07 PMSascha
09/07/2020, 12:07 PMnode_modeules/.prisma
which is never generated.Sascha
09/07/2020, 12:07 PMschema.prisma
looks like this tho:
generator client {
provider = "prisma-client-js"
output = "./generated/client"
}
Sascha
09/07/2020, 12:07 PMRyan
09/07/2020, 12:08 PMgenerator prisma {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DB_URL")
}
model User {
id Int @id @default(autoincrement())
name String
}
Without a custom generated folderRyan
09/07/2020, 12:09 PMimport { PrismaClient } from './generated/client'
const prisma = new PrismaClient()
prisma.$use(async (params, next) => {
console.log('middlware called')
const result = next(params)
return result
})
const nexusPrisma = nexusSchemaPrisma({
experimentalCRUD: true,
prismaClient: (ctx: Context) => ctx.prisma,
})
const server = new ApolloServer({
schema,
context: createContext, // pass the instance of Prisma Client here
playground: true,
})
Sascha
09/07/2020, 12:13 PMoutput = "./generated/client"
.. no it generates the client in the right directory.Sascha
09/07/2020, 12:13 PMSascha
09/07/2020, 12:13 PM