1

Amplify automatically generates mutations for delete like this:

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

and this is how I call it in my App.js

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

It returns an error like this. Seems like the data has not been passed

message: "The variables input contains a field name 'index' that is not defined for input object type 'DeleteTodoInput' "
Hector
  • 45
  • 7
  • `DeleteTodoInput` description and actual (before call API) `result` ? – xadm Feb 15 '20 at 00:52
  • can you clearly explain this please, I'm pretty new to this – Hector Feb 15 '20 at 01:35
  • show this type definition - even generated is defined somewhere - you must know what it contains .... https://www.howtographql.com/ – xadm Feb 15 '20 at 11:48

2 Answers2

0

I'm not sure what result is but you can try:

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

await API.graphql(graphqlOperation(mutations.deleteTodo, {input: { ...result }}));
Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
0

Problem is with the result variable. It should be {result} and it should have the index. Incase you dont have index remove it from the query

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

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