> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codenullapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Submit Datasource (Graphql)

> A submit datasource allows a Form component to save the data.

A submit datasource allows a Form component to save the data.

You can perform two types of actions

* Create
* Update

## Automatic generation

This feature is helpful if you don't want to start from scratch to configure your submit datasource

<figure>
  <img src="https://mintcdn.com/codenull/fUND-Qmj85v5Oam-/images/mJLOcCClx2dopquFzAVA.png?fit=max&auto=format&n=fUND-Qmj85v5Oam-&q=85&s=95d5a22b378c96c66019f0c2a9ba88a8" alt="" width="1356" height="752" data-path="images/mJLOcCClx2dopquFzAVA.png" />

  <figcaption />
</figure>

**Entities**: Choose the entity you want to save/update

**Fields**: Choose the fields you want to save in the submit datasource

**Query type**: choose ***create*** or ***update***

Then click on the **Generate** button. This will generate the basic submit datasource configuration for you

## Configure a submit datasource manually

There are two main configurations needed to configure a submit action

* Query
* Variables

### Query

Here, you should define the GraphQL mutation you want to execute during the submit action

<figure>
  <img src="https://mintcdn.com/codenull/9RtgKoAtzvpYtN-c/images/Pt03tlw3aHD2b0mbCX0N.png?fit=max&auto=format&n=9RtgKoAtzvpYtN-c&q=85&s=26bee7d471e1520b909721916e3083d7" alt="" width="1216" height="392" data-path="images/Pt03tlw3aHD2b0mbCX0N.png" />

  <figcaption />
</figure>

```graphql theme={null}
mutation createPersona($data: PersonaInput) {
  createPersona(data: $data) {
    Id
    Foto
    Identificacion
    NombreCompleto
    Edad
    Sexo
    Telefono
    Email
  }
}
```

### Datasource variables

<figure>
  <img src="https://mintcdn.com/codenull/9RtgKoAtzvpYtN-c/images/MiassBCni4QIFM7jdNIn.png?fit=max&auto=format&n=9RtgKoAtzvpYtN-c&q=85&s=7002f8d9e4b491a3cc9c2c958e756563" alt="" width="1232" height="286" data-path="images/MiassBCni4QIFM7jdNIn.png" />

  <figcaption />
</figure>

**Generate Variables Using Context Value**: If true, the datasource will take all values in the form context and submit them

**Variables List**: Here, you can add all data values you want to send in the request. You can combine this option with the Generate variables using context value.

### **Other settings**

**Refetch Queries:** Allows to execute a query, which is helpful, for instance, when you want to refresh the datasource of the form and get the data from the server after the submit is completed

<figure>
  <img src="https://mintcdn.com/codenull/fUND-Qmj85v5Oam-/images/iXZHLm6h5g90ETFZV9Ql.png?fit=max&auto=format&n=fUND-Qmj85v5Oam-&q=85&s=5080f810f8f41c83b1977a8925ef4e7c" alt="" width="1294" height="98" data-path="images/iXZHLm6h5g90ETFZV9Ql.png" />

  <figcaption />
</figure>

**Data Path**: This is useful when you want to use the Generate Variables Using Context Value

**On Completed Configurations:** This will determine the behaviour after the submit action is completed

<figure>
  <img src="https://mintcdn.com/codenull/fUND-Qmj85v5Oam-/images/mmHUdpnW3Pm8LHHB4gVK.png?fit=max&auto=format&n=fUND-Qmj85v5Oam-&q=85&s=276de0dc4ee4b3fa8c5306b3d570a772" alt="" width="1252" height="404" data-path="images/mmHUdpnW3Pm8LHHB4gVK.png" />

  <figcaption />
</figure>

## Mutation examples

### Submit a single entity

```graphql theme={null}
mutation createPersona($data: PersonaInput) {
  createPersona(data: $data) {
    Id
    Foto
    Identificacion
    NombreCompleto
    Edad
    Sexo
    Telefono
    Email
  }
}
```

### Submit an entity with child entities (Array)

Codenull allows the creation of multiple entities in the same request. You need to make sure to send all data in the same way as the tables are related to each other.

In the next example, a Seguimiento has multiple Etapas

```graphql theme={null}
# This mutation will create a Seguimiento but also the Etapas child´s entity
mutation createSeguimiento($data: SeguimientoInput) {
  createSeguimiento(data: $data) {
    Id
    Nombre
    IglesiaId
    Etapas {
      Id
      SeguimientoId
      Nombre
      Descripcion
    }
  }
}   
```

<figure><img src="https://mintcdn.com/codenull/9RtgKoAtzvpYtN-c/images/1IFIxgqlBJdmlDZUQBGv.png?fit=max&auto=format&n=9RtgKoAtzvpYtN-c&q=85&s=44d231ceeead579aee1db7d36b6e42c4" alt="" width="762" height="284" data-path="images/1IFIxgqlBJdmlDZUQBGv.png" /><figcaption><p>The list of variables should have the Etapas field</p></figcaption></figure>

The variable data.Etapas should have the array of Etapas that will be created among the Seguimiento

This is how the **request data** should look

<figure>
  <img src="https://mintcdn.com/codenull/9RtgKoAtzvpYtN-c/images/a3QCYF3qDFvZ5iwMxKHV.png?fit=max&auto=format&n=9RtgKoAtzvpYtN-c&q=85&s=00e2c23cb421e7c999e8bb2b303608ed" alt="" width="988" height="512" data-path="images/a3QCYF3qDFvZ5iwMxKHV.png" />

  <figcaption />
</figure>

The next is a full example of a subimt with a parent and child entities:

```javascript theme={null}
// Query
mutation createUsuario($data: UsuarioInput) {
  createUsuario(data: $data){
    Id
    Nombre
    Apellidos
    Correo
    IglesiaId
    PersonaId
    RolesxUsuarios{
      Id
      UsuarioId
      RoleId
    }
  }
}

// Variables  
[
    {
      "type": "nested",
      "name": "data",
      "variables": [
        {
          "type": "context",
          "name": "Nombre",
          "value": "Nombre"
        },
        {
          "type": "context",
          "name": "Apellidos",
          "value": "Apellidos"
        },
        {
          "type": "context",
          "name": "Identificacion",
          "value": "Identificacion"
        },
        {
          "type": "session",
          "name": "IglesiaId",
          "value": "user.IglesiaId"
        },
        {
          "type": "context",
          "name": "PersonaId",
          "value": "PersonaId"
        },
        {
          "type": "context",
          "name": "Correo",
          "value": "Correo"
        },
        {
          "type": "context",
          "name": "Clave",
          "value": "Clave"
        },
        {
          "type": "context",
          "name": "RolesxUsuarios",
          "value": "RolesxUsuarios"
        }
      ]
    }
  ],
}
```

### Submit an entity with a parent entity

**Query**

```graphql theme={null}
mutation createUser($data: UsuarioInput) {
  signUp(data: $data) {
    Id
    IglesiaId
    Correo
    Iglesia {
      Id
      Nombre
      Telefono
      Direccion
      Pais
      Personas{
        Id
        IglesiaId
        Identificacion
        NombreCompleto
        Clasificacion
        Perfil
        FechaNacimiento
        Edad
        Email
      }
    }
    RolesxUsuarios {
      Id
      RoleId
    }
  }
}

```

**Variables List**

<figure>
  <img src="https://mintcdn.com/codenull/9RtgKoAtzvpYtN-c/images/WEDgMYgKtydev7bMtjQb.png?fit=max&auto=format&n=9RtgKoAtzvpYtN-c&q=85&s=3bebbf05910fba98dda38efaae3f51d6" alt="" width="1234" height="582" data-path="images/WEDgMYgKtydev7bMtjQb.png" />

  <figcaption />
</figure>

<figure>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/codenull/files/pfezsgoFdxf4QutJUynL" alt="" />

  <figcaption />
</figure>
