notiz-dev / nestjs-prisma-starter

Starter template for NestJS 😻 includes GraphQL with Prisma Client, Passport-JWT authentication, Swagger Api and Docker
MIT License
2.32k stars 336 forks source link

Prisma2 support #121

Closed marcjulian closed 4 years ago

marcjulian commented 5 years ago

Replacing Prisma with Prisma2 https://github.com/prisma/prisma2#readme

marcjulian commented 5 years ago

https://github.com/fivethree-team/nestjs-prisma-starter/tree/prisma2 work in progress

hegelstad commented 4 years ago
prisma/seed.ts:1:10 - error TS2614: Module '".../node_modules/@generated/photon"' has no exported member 'Photon'. Did you mean to use 'import Photon from ".../node_modules/@generated/photon"' instead?

1 import { Photon } from '@generated/photon';

Fixed by using default imports: import Photon from '@generated/photon';

marcjulian commented 4 years ago

@hegelstad which version of prisma2 are you using? Since prisma2 preview-12 the import of Photon has change see here https://github.com/prisma/prisma2/releases/tag/2.0.0-preview-12

hegelstad commented 4 years ago

I followed the steps in the readme, so I suppose npm install -g prisma2 doesn't install the latest preview?

marcjulian commented 4 years ago

Yes it should install the latest prisma2 preview, you can check the version with prisma2 -v

mso1985 commented 4 years ago

When creating a new model you need to add it to schema.prisma AND inside src/models right ?

marcjulian commented 4 years ago

Yes you have to add a new model to prisma/schema.prisma

model Movie {
 id String
 ...
}

Then you create a model in src/models/movie.ts like

@ObjectType()
export class User {
  @Field()
  id: string;

 // Add properties here, add @Field() to properties which should be exposed in the API
 // Add properties without @Field() which are private (such as Password and other sensitive informations) 

}

You can learn more about prisma models in there docs https://github.com/prisma/prisma2#readme. Also I recommend checking out Nestjs documentation and type-graphql

Jayphen commented 4 years ago

I'd love to see an example of how you might integrate Nexus!

marcjulian commented 4 years ago

@Jayphen I tried out using Nexus with nestjs and prisma1. You can find an example here https://github.com/marcjulian/nestjs-prisma-nexus. I have stopped using nexus with nestjs since type-graphql has better nestjs support. There is also an integration planned for prisma2 https://github.com/MichalLytek/type-graphql/issues/476

Jayphen commented 4 years ago

Thanks for the links. I tried last night to get it working with prisma2 and got most of the way, but with some issues. I'll stick to type-graphql for now!