[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
I'm trying to integrate Prisma with NestJS thanks to the new shiny Prisma Client.
The Prisma CLI generates a TS file with a Prisma class and a prisma instance of that class.
I'm willing to create an injectable service that makes use of this client (as it is done in the examples section with prisma-binding).
Unfortunately, event if it does not throw any error, the builder seems frozen :
[Nest] 24944 - 2018-9-27 17:31:39 [NestFactory]
Starting Nest application...
[Nest] 24944 - 2018-9-27 17:31:39 [InstanceLoader] ApiModule dependencies initialized +18ms
[Nest] 24944 - 2018-9-27 17:31:39 [InstanceLoader] AppModule dependencies initialized +1ms
I have tried :
CLASSIC SERVICE (does not work)
import { Injectable } from '@nestjs/common';
import { Prisma } from 'server/api/generated';
@Injectable()
export class ApiService extends Prisma {
constructor() {
super();
}
}
CUSTOM PROVIDER AS VALUE (does not work)
import { prisma } from 'server/api/generated';
const apiProvider = {
provide: 'ApiService',
useValue: prisma,
};
@Module({
providers: [apiProvider],
exports: [apiProvider],
})
export class ApiModule {}
CUSTOM PROVIDER AS CLASS (does not work)
import { Prisma } from 'server/api/generated';
const apiProvider = {
provide: ApiService,
useClass: Prisma,
};
@Module({
providers: [apiProvider],
exports: [ApiService],
})
export class ApiModule {}
CUSTOM PROVIDER AS FACTORY (does not work)
import { prisma, Prisma } from 'server/api/generated';
const apiProvider = {
provide: 'ApiService',
useFactory: () => new Prisma() // or just prisma,
};
@Module({
providers: [apiProvider],
exports: [apiProvider],
})
export class ApiModule {}
CLASSIC SERVICE WITH INSTANCE (works)
import { Injectable } from '@nestjs/common';
import { prisma, Prisma } from 'server/api/generated';
@Injectable()
export class ApiService {
prisma: Prisma;
constructor() {
this.prisma = prisma;
}
}
But not what I want.
Working injection of either the class or the value without the need to use a property.
endpoint: https://eu1.prisma.sh/public-agatepuma-476/my-app/dev
datamodel: datamodel.graphql
seed:
import: seed.graphql
generate:
- generator: typescript-client
output: ../src/prisma/generated
hooks:
post-deploy:
- prisma generate
prisma.service.ts change the import : import { Prisma } from './generated';
Use the last Prisma Client tool.
Nest version: 5.3.10
For Tooling issues:
- Node version: 8.11.1
- Platform: Windows
Others:
cc @cschroeter
@gbouteiller The new Prisma Client is still in beta. We are going to revise this chapter after the new client is released.
@kamilmysliwiec Not an issue
Ah and by the way @gbouteiller, next time you update core dependencies and something is not working, consider to open a feature request and not a bug. Those version numbers are not there by coincidence. 馃
@cschroeter Prisma Client was released 2 days ago with 1.17 version ( the beta is now 1.18 ).
Ah and by the way, I updated the dependencies because as I mentioned, the tool is pretty new and not available in 1.16, so this was the only way to use it. But you are right about something though 馃 : I'm not used with the template for issues so I checked the wrong box, my bad.
Okay. I will have a look at the new client tomorrow.
@kamilmysliwiec Mh I fear this has something to do with the DI mechanism. If I define the Prisma Client, without injecting it - no problem. As soon as I inject it - the app freezes. The client looks like pretty much straight forward.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
// import { Prisma, prisma } from './prisma/client';
@Module({
controllers: [AppController],
providers: [
AppService,
{
provide: Prisma,
useValue: prisma,
},
],
})
export class AppModule {}
import { Get, Controller } from '@nestjs/common';
import { AppService } from './app.service';
// import { Prisma } from './prisma/client';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
// private readonly prisma: Prisma,
) {}
@Get()
async root(): Promise<string> {
// console.log(this.prisma);
return this.appService.root();
}
}
I've provided an repo to reproduce the issue https://github.com/cschroeter/nestjs-prisma-117
@gbouteiller I've updated the graphql-prisma example, see PR https://github.com/nestjs/nest/pull/1136
@cschroeter so I think that, in the end, it can be tagged as a bug as like you also experienced, prisma-client cannot be injected.
About the PR, you don't seem to use prisma-client and I prefer to stick to it as it is the direction taken by the Prisma team and as I already have a workaround ( I just initialize a property of my service with it for now ).
thank you for your time and your investigation, I hope we'll be able to understand it soon ;).
I would suggest creating a corresponding issue @cschroeter, perhaps, we should think about how to solve it.
As it is closed now, have you created a corresponding issue that I can subscribe to?
Hello, so has a corresponding issue indeed been created please?
I've had no issues with the Prisma client at all in Nest, perhaps you're just doing something wrong in your app?
https://github.com/ForetagInc/fullstack-boilerplate/tree/master/apps/api/src
@marcus-sa It looks like you don't seem to use the prisma client as I don't see generate in your prisma.yml config. So it's normal that you don't have the issue.
@kamilmysliwiec @cschroeter did you create an issue after all?
@gbouteiller yes I am, lol, you need to configure it properly.
https://github.com/ForetagInc/fullstack-boilerplate/blob/master/.graphqlconfig.yml
Can you provide a repository so I cant to try reproduce your issue?
There's no problems whatsoever no matter how I try to instantiate the provider.
https://github.com/ForetagInc/fullstack-boilerplate/blob/master/apps/api/src/app/prisma/prisma.service.ts
@marcus-sa I've seen your code and I don't want to create a debate on prisma-client here, but what you are using is prisma-binding which is the solution that Prisma first proposed. Since then, they introduced prisma-client which is different from prisma-binding.
So please it would be more helpful to read the thread completely instead of saying that something is wrong or not configured properly and link to unrelated code ;).
As I already mentioned, everything works if you use prisma-binding or the prisma-client as a property of a service but not as a service itself. You can easily reproduce the issue by following what I've described at the top of the thread.
@marcus-sa I'm afraid @gbouteiller is correct, you're not using prisma-client in your code, you're using prisma-binding -- please read here for more information: https://www.prisma.io/docs/prisma-client/setup/generating-the-client-rsc1/
@kamilmysliwiec @cschroeter I can also get in touch with the Prisma team if you're having other difficulties. Can we help somehow? Thank you!
@picosam @gbouteiller Sorry for the late response. I became a father so the last weeks were a bit stressful. 馃嵓
I created a reproduction repo and a ticket here https://github.com/nestjs/nest/issues/1277
@picosam I don't think this has something to do with Prisma itself, its more about the way Nest deals with async constructor functions. Unfortunately I am not that familiar with that part of Nest. Hopefully @kamilmysliwiec can give us some input here. 馃檶
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@picosam @gbouteiller Sorry for the late response. I became a father so the last weeks were a bit stressful. 馃嵓
I created a reproduction repo and a ticket here https://github.com/nestjs/nest/issues/1277
@picosam I don't think this has something to do with Prisma itself, its more about the way Nest deals with async constructor functions. Unfortunately I am not that familiar with that part of Nest. Hopefully @kamilmysliwiec can give us some input here. 馃檶