Hi, how can I seed data with cross dependencies, i...
# prisma-whats-new
m
Hi, how can I seed data with cross dependencies, i.e. first seed a user and then use this users id to create a dependent object in
seed.graphql
?
n
I'm aware of two options: - use nested mutations - use a seeding script. I collected potential improvements for seeding workflows here: https://github.com/graphcool/prisma/issues/1536
m
Thanks @nilan! Do you have a sample of how either one would look? If writing a seeding script, what is the right entry point and how would i access the
ctx
variable?
n
Nested mutations are described here: https://www.prismagraphql.com/docs/reference/prisma-api/mutations-ol0yuoz6go#nested-mutations you can create a new instance of a Prisma binding in your script, the same way you do this in the boilerplates
m
Hi, thanks @nilan. Ok, so I see what you mean with nested mutations now. However, this means that when creating an object in the prisma seed file, I need to create all its dependencies along with it through nested
create:
and cannot refer to a previously seeded object via
connect:
, since I cannot access its id. Am I right or misunderstanding? When you say connect to prisma via a binding like in the boilerplate, do you mean creating an instance like so?
Copy code
const prisma = new Prisma({
      endpoint: process.env.PRISMA_ENDPOINT,
      secret: process.env.PRISMA_SECRET,
      debug: true 
    })
Could I also access the prisma binding from my server object created in the boilerplates index? Or is that not desired? Im not sure I understand what the context function means exactly.
n
k
😄
i used a unique field
slug
to do the matching between products and brands
m
Great, just what I was looking for! Thanks guys!