跳转到内容

变更单条记录

您可以使用 8base 自动生成的 GraphQL 变更操作来创建、更新和删除单个表记录。

在以下示例中,我们有一个名为 students 的表,其中包含諸如 firstNameemailage 等字段和关系。

使用定义记录数据的输入参数创建新记录。

请求

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

响应

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

使用 id 和输入参数更新记录。

请求

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

响应

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

使用 id 参数删除记录。

请求

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

响应

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