Salta ai contenuti

Mutazione di Record Individuali

Puoi creare, aggiornare ed eliminare singoli record di tabella utilizzando le operazioni di mutazione GraphQL generate automaticamente da 8base.

Negli esempi seguenti, abbiamo una tabella chiamata students, che contiene campi e relazioni come firstName, email, age.

Crea un nuovo record utilizzando l’argomento di input che definisce i dati dei record.

Richiesta

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
}
}
}

Risposta

{
"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"
}
}
}
}

Aggiorna un record utilizzando gli argomenti id e input.

Richiesta

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

Risposta

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

Elimina un record utilizzando l’argomento id.

Richiesta

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

Risposta

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