0

I am creating an ipotetic CRUD, based on a business that I have studied. The problem is that i try to make a nested mutation as shown in lighthouse docs but with three levels of depth in the relationship as {client has many contacts and contacts has many emails}

I do the following in the schema.graphql:

type Mutation {
    createClient (input: createClientInput! @spread): Client @create
}

input createClientInput {
    name: String!
    address: String!
    NIT: String
    ...    
    contracts: CreateContactsRelation
}

input CreateContactsRelation {
    create: [CreateContactInput!]
}

input CreateContactInput {
    name: String
    position: String
    emails: CreateEmailRelation # this does'n work
}

input CreateEmailRelation {
    create: [CreateEmailInput!]
}

input CreateEmailInput {
    email: String!
}

run the mutation

mutation{
  crearCliente(input: {
    nombre: "prueba graphql crear 4"
    direccion: "prueba"
    NIT: "3225"
    abreviatura: "asas"
    OSDE: "prub"
    organismo: "asas"
    observaciones: "con contacto"
    contactos: {
      create: [
        {
          nombre: "periqito peres"
          cargo: "director"
          correos: {
            create: [
              {
                email: "perez@gmail.com"
              }
              {
                email: "perez@enet.cu"
              }
            ]
          }
        }
        {
          nombre: "joaqin gomez"
          cargo: "contador"
          correos: {
            create: [
              {
                email: "joaqin@gmail.com"
              }
              {
                email: "joaqin@enet.cu"
              }
            ]
          }
        }
      ]
    }
  }){
    id
    nombre
    contactos{
      id
      nombre
      cargo
      correos{
        id
        email
      }
    }
  }
}

and the output is

{
  "data": {
    "crearCliente": {
      "id": "53",
      "nombre": "prueba graphql crear 4",
      "contactos": [
        {
          "id": "46",
          "nombre": "periqito peres",
          "cargo": "director",
          "correos": [] <--------------not email 
        },
        {
          "id": "47",
          "nombre": "joaqin gomez",
          "cargo": "contador",
          "correos": [] <--------------not email
        }
      ]
    }
  }
}

As you can see, emails are not created. Anyone know how it could be resolved?

eberna
  • 3
  • 1

1 Answers1

0

you have to connect each table relations with the id i create this example for you to understand this :

enter image description here

enter image description here

stilo bit
  • 144
  • 1
  • 2