# Submit Datasource (Graphql)

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="/files/mJLOcCClx2dopquFzAVA" alt=""><figcaption></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="/files/Pt03tlw3aHD2b0mbCX0N" alt=""><figcaption></figcaption></figure>

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

### Datasource variables

<figure><img src="/files/MiassBCni4QIFM7jdNIn" alt=""><figcaption></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="/files/iXZHLm6h5g90ETFZV9Ql" alt=""><figcaption></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="/files/mmHUdpnW3Pm8LHHB4gVK" alt=""><figcaption></figcaption></figure>

## Mutation examples

### Submit a single entity

```graphql
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
# 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="/files/1IFIxgqlBJdmlDZUQBGv" alt=""><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="/files/a3QCYF3qDFvZ5iwMxKHV" alt=""><figcaption></figcaption></figure>

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

```javascript
// 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
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="/files/WEDgMYgKtydev7bMtjQb" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/pfezsgoFdxf4QutJUynL" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codenull.gitbook.io/dev/configurations/components/datasources/submit-datasource-graphql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
