hey folks, i need some help with the NestJs code f...
# orm-help
v
hey folks, i need some help with the NestJs code first approach. I am starting to learn and implement Prisma2. I want to understand how do we generate the prisma schema? I see that schema.gql gets generated automatically. @ryan Could you please help me on this? I
m
Hey Venu πŸ‘‹πŸ» Do you mind giving more context?
Also I believe you wanted to mention @Ryan πŸ˜„
For the Prisma schema, which you use to define your database models, you can either write it from scratch or introspect an existing database using
npx prisma db pull
v
Thanks Mahmoud for the response. Basically am following the code first approach for NestJs GraphQL
I want to integrate prisma2
Inorder to use prisma2 in code first approach, do we need to generate schema.prisma or does it auto generated from schema.gql?
m
It’s actually the other way around. You need to define your database models and then you can generate a GraphQL schema if you want
This is an example of generating the GraphQL API from your database schema
v
Okie.. that becomes SDL approach..
m
Not really, you're defining your schema using TS and then this generates your
schema.graphql
file
1. You define your database models 2. You create your schema using a code first approach and include prisma queries in your resolvers Now if you want to generate your API from your database schema you can do that using type-graphql or nexus (each one of those libraries have a generator plugin you can use)
Does that make sense?
v
that makes sense! thanks a lot!