How to connect nodes in a relation to another node that you create at the same time


Consider the structure below

mutation createBusiness {
    data: {
      staff: { create: [{ name: "Petros", email: "" }] }
      services: {
        create: [
            name: "Hair Wash"
            duration: 20
            staff: { ... }
  ) {

So basically a business offers services and has staff . However, the services are run by specific staff members or all of them. So the problem is that at the point of creating the business, the staff members are created and the services need to be created as well.

However I am struggling to connect the services staff members to the staff created at the same time.

Any ideas if at all possible?



The best approach for your current situation that I can currently think of is to create business and service in separate calls.

That way will allow you to connect the specific staff members to the service using their ids that are being returned to you in the first call.

Let me know if this approach will work for you :slight_smile:


Hey @pitops,

I think @pantharshit00’s suggestion is probably the way to go. Would you mind posting your full datamodel (or at least the relevant parts with Service, Staff and Business)?


Hey @pantharshit00 so yeah thats what I actually ended up doing. My question is, isn’t that suboptimal? In terms of performance? Or does prisma underneath behave the same way if i were to do it on a single mutation?

@nikolas sure thing - I will post only the relevant parts

type Business {
  id: ID! @unique
  name: String!
  services: [Service!]!
  staff: [Staff!]!

type Staff {
  id: ID! @unique
  business: Business!

type Service {
  id: ID! @unique
  staff: [Staff!]!


There should not be any significant impact in performance Prisma batches up things for you. You should be good here, don’t get too worried :slightly_smiling_face:.


This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.