在Amplify ReactJs中删除和更新Graphql突变

时间:2020-02-15 00:44:36

标签: graphql aws-amplify graphql-mutation

Amplify自动为删除生成突变,如下所示:

export const deleteTodo = /* GraphQL */ `
 mutation DeleteTodo($input: DeleteTodoInput!) {
  deleteTodo(input: $input) {
   index
   body
   hasRead
 }

这就是我在App.js中的称呼方式

await API.graphql(graphqlOperation(mutations.deleteTodo, {input: result}));

它返回这样的错误。似乎数据尚未传递

message: "The variables input contains a field name 'index' that is not defined for input object type 'DeleteTodoInput' "

1 个答案:

答案 0 :(得分:0)

我不确定result是什么,但是您可以尝试:

const result = {
  index: 1,
  body: 'blabla',
  hasRead: true,
}

await API.graphql(graphqlOperation(mutations.deleteTodo, {input: { ...result }}));