Open scleriot opened 4 years ago
Can you show the part of app.ts please? (You can remove the parts you don't want to show)
Sure:
import { server, settings, use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'
import { PrismaClient } from '@prisma/client'
// ...
server.express.use((req, res, next) => {
req.prisma = new PrismaClient()
next()
})
Right now my workaround for completing the build is commenting line 78 of node_modules/nexus/dist/lib/tsc.js:
if (allDiagnostics.length > 0) {
console.log(project.formatDiagnosticsWithColorAndContext(allDiagnostics));
// throw new Error(project.formatDiagnosticsWithColorAndContext(allDiagnostics));
}
According to the tutorial you should either just do
use(prisma())
to make prisma available in the context (as db
I think) or you can use:
const db = new PrismaClient();
use(
prisma({
client: {
instance: db,
},
features: {
crud: true, // only if you want that
},
})
);
if you need to do customizations.
@mohe2015 Thanks, but this issue is not about Prisma usage, but a bug report regarding TypeScript typechecking done by nexus build
@scleriot I know but the error Property 'prisma' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>'.
looks like you are not supposed to manipulate the request object. Instead you are supposed to manipulate the context object e.g. using my method or using schema.addToContext
Edit:
schema.addToContext(async ({req, res}) => {
return {
db: new PrismaClient(), // If you really want to create a new one for every request
userId: getItSomehow(req)
};
});
Actually I'm trying no extend not only NexusContext type but also Express
I should be able to extend any typings, in types/ directory for example as explained here: https://nexusjs.org/guides/project-layout#local-package-typings.
Works well with nexus dev
, error happens only at build time
Description
When building with
nexus build
I get typing error that I don't get when runningnexus dev
:Local typing is defined in:
express/index.d.ts looks like this:
Here is the corresponding tsconfig.json:
Nexus Report
I get the following error when doing nexus report: