Ir al contenido

Mutando Registros Individuales

Puede crear, actualizar y eliminar registros de tablas individuales utilizando las operaciones de mutación GraphQL generadas automáticamente por 8base.

En los siguientes ejemplos, tenemos una tabla llamada students, que contiene campos y relaciones como firstName, email, age.

Cree un nuevo registro utilizando el argumento de entrada que define los datos del registro.

Solicitud

mutation MyMutation1 {
createStudents(
input: {
firstName: "John",
lastName: "Doe",
email: "john.doe@example.com",
age: 24,
city: "2900562f-d036-486d-be98-9ebf064c27fe"
}
) {
id
firstName
lastName
email
age
city {
id
nameCity
}
}
}

Respuesta

{
"data": {
"createStudents": {
"id": "2685ec12-a4c7-491d-a155-d0b09190993b",
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"age": 24,
"city": {
"id": "2900562f-d036-486d-be98-9ebf064c27fe",
"nameCity": "Houston"
}
}
}
}

Actualice un registro utilizando los argumentos id e input.

Solicitud

mutation MyMutation1 {
updateStudents(
id: "2685ec12-a4c7-491d-a155-d0b09190993b",
input: {
age: 23
}
) {
id
firstName
age
}
}

Respuesta

{
"data": {
"updateStudents": {
"id": "2685ec12-a4c7-491d-a155-d0b09190993b",
"firstName": "John",
"age": 23
}
}
}

Elimine un registro utilizando el argumento id.

Solicitud

mutation MyMutation1 {
deleteStudents(
id: "2685ec12-a4c7-491d-a155-d0b09190993b"
)
}

Respuesta

{
"data": {
"deleteStudents": true
}
}