Title
j

Jawad Sefiani

11/19/2020, 7:32 PM
Hi everyone! How do I use Prisma inside of a monorepo managed by Lerna? Multiple packages will depend on Prisma's types, so what do you advise?
Do I have to create a dedicated package for Prisma or can I just initialize it in the root of my project?
b

Ben

11/19/2020, 7:56 PM
in our use case we have 2 api packages that have there types generated for each package using the
--schema=./schema.prisma'
in the generate command to point to same location, not sure if thats best practices but it works fine
j

Jawad Sefiani

11/19/2020, 8:17 PM
@Ben so the schema.prisma file is located in the root?
b

Ben

11/19/2020, 8:18 PM
we have it pulled into its own project at time being
j

Jawad Sefiani

11/19/2020, 8:20 PM
Something like this?
b

Ben

11/19/2020, 8:21 PM
we just have like
packages/db/schema.prsima
then in another package packages/api
wee call yarn generate inside thata
oh and we are using yarn with workspaces which may be different
"workspaces": {
    "nohoist": [
      "@prisma/*"
    ]
  }
so we dont bring prisma up to root node modules
it will stay in that packages/api/node_modules folder
j

Jawad Sefiani

11/19/2020, 8:23 PM
So
db
is considered a package too?
b

Ben

11/19/2020, 8:23 PM
yeah
it just a folder really no package.json or anything
j

Jawad Sefiani

11/19/2020, 8:24 PM
ow okay
I actually need the same schema but in 1 package I don't need any generators while in the other package I do
b

Ben

11/19/2020, 8:25 PM
so in my messed up example i would call
generate --schema=../db/schema.prisma'
or something similar
j

Jawad Sefiani

11/19/2020, 8:25 PM
but where will it generate the types?
in db folder or in api?
b

Ben

11/19/2020, 8:26 PM
it will generate its types for thee api folder since thats where i call that commaand
j

Jawad Sefiani

11/19/2020, 8:27 PM
so you call the command in the api folder?
and what about dependencies like Prisma Client?
where did you add them to?
b

Ben

11/19/2020, 8:29 PM
i call commanad where i want it to genereate client
@prisma/cli is in api folder right now
j

Jawad Sefiani

11/19/2020, 8:30 PM
hhm and what if you need Prisma in another package?
then you need to add that dependency again?
b

Ben

11/19/2020, 8:30 PM
we run generate in that folder too
issue we have which you might not haave is we have multiple data sources, so client may be different per package in our monorepo
j

Jawad Sefiani

11/19/2020, 8:32 PM
ow alright that's indeed different
I only have 1 source, a PostgreSQL DB
j

Jonathan Romano

11/19/2020, 8:32 PM
What about having a db package where the index file just exports
@prisma/client
?
b

Ben

11/19/2020, 8:33 PM
since your using lerna you could test to see if hoisting prisma to root works, and in your case thats all you need
j

Jawad Sefiani

11/19/2020, 8:36 PM
so I should add it to the root package.json?
@Jonathan Romano Yeah I could try that