变更单条记录
您可以使用 8base 自动生成的 GraphQL 变更操作来创建、更新和删除单个表记录。
在以下示例中,我们有一个名为 students 的表,其中包含諸如 firstName、email、age 等字段和关系。
创建单条记录
Section titled “创建单条记录”使用定义记录数据的输入参数创建新记录。
请求
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" } } }}更新单条记录
Section titled “更新单条记录”使用 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 } }}删除单条记录
Section titled “删除单条记录”使用 id 参数删除记录。
请求
mutation MyMutation1 { deleteStudents( id: "2685ec12-a4c7-491d-a155-d0b09190993b" )}响应
{ "data": { "deleteStudents": true }}