Hey guys I have a question... How do I connect the...
# prisma-whats-new
j
Hey guys I have a question... How do I connect the type PatientDocumentation everytime I create a PatientProfile in a mutation? I can do that in Graph.cool GUI connecting the node, but how do I do it in a mutation?! Sorry i know this should be basic, but i cant connect the id with each other...
Copy code
type PatientProfile @model {
  createdAt: DateTime!
  id: ID! @isUnique
  updatedAt: DateTime!
  name: String!
  number: Int! @isUnique
  lastName: String
  lastViewed: String
  patientDocumentation: PatientDocumentation @relation(name: "DocumentationOnPatient")
}
Copy code
type PatientDocumentation @model {
  hours12: String
  id: ID! @isUnique
  natural: String
  patientProfile: PatientProfile @relation(name: "DocumentationOnPatient")
  profile: String
  video: String
  withdrawn: String
  xray: String
}
m
Simple send the Id
or what the problem is? maybe I misunderstood
You want to create the PatientDocumentation for the PatientProfile while PatientProfile is creating?
t
You can add
patientDocumentationId
to your mutation payload:
Copy code
mutation {
  createPatientProfile( ... patientDocumentationId: <id goes here>) {
    id
  }
}
this will create the connection, check the docs on Relation Mutations for more info: https://docs-next.graph.cool/docs/reference/graphql-api/mutation-api-ol0yuoz6go#relation-mutations
👍 1
j
thx @Maslov for your time, yeah the problem is really the id, i want to create the profile and the documentation id at the same time and connect them..
m
@joao.santos you can use server function
j
oh ok... I thought it was an easy thing to do in the mutation... I'll try that.. thx never used functions.. lol
t
You can use nested mutations for that:
Copy code
mutation {
    createPatientProfile( ...
        patientDocumentation: {
            hours12: "hours value"
            natural: "natural value"
            profile: "profile value"
            video: "video value"
            withdrawn: "withdrawn value"
            xray: "xray value"
        }
        ...) {
        id
    }
}
1
whoops formatting went off 🙂
j
yeah 😄
i was writing
Copy code
mutation createPatientProfileAndDocumentation {
  createPatientProfile(
    name: "name"
    lastName: "lastName"
    number: 6
    patientDocumentation: {
      profile: "profile"
      natural: "natural"
    }
  ) {
    id
     patientDocumentation{
      id
    }
  }
}
i di this and it worked
thx @taikn
thx guys
it was simple.. 😄