Error: Invalid AST Node: {"input":"** } on graphql mutation (Amplify client)
Asked Answered
C

1

8

I tried to use example schema on api doc("https://aws-amplify.github.io/docs/cli-toolchain/graphql?sdk=js") like below on Many-To-Many Connections

type Post @model {
  id: ID!
  title: String!
  editors: [PostEditor] @connection(keyName: "byPost", fields: ["id"])
}

# Create a join model and disable queries as you don't need them
# and can query through Post.editors and User.posts
type PostEditor
  @model(queries: null)
  @key(name: "byPost", fields: ["postID", "editorID"])
  @key(name: "byEditor", fields: ["editorID", "postID"]) {
  id: ID!
  postID: ID!
  editorID: ID!
  post: Post! @connection(fields: ["postID"])
  editor: User! @connection(fields: ["editorID"])
}

type User @model {
  id: ID!
  username: String!
  posts: [PostEditor] @connection(keyName: "byEditor", fields: ["id"])
}

I created all items and then I tried to delete them but I failed especially on PostEditor.

There is a mutation to delete PostEditor so I called it like below

API.graphql(graphqlOperation((deletePostEditor, {input: {id},})))

It fails with below error message.

Error: Invalid AST Node: {"input":"b2f7064c-af32-49cd-8c87-*******"}

I think I provided right ID. I checked it on query.

Crowfoot answered 29/12, 2019 at 2:10 Comment(3)
is it possible to share client side code,deletePostEditorTorquay
the code is generated by amplify codegen. the code is like below.Crowfoot
export const deletePostEditor = mutation DeletePostEditor( $input: DeletePostEditorInput! $condition: ModelPostEditorConditionInput ) { deletePostEditor(input: $input, condition: $condition) { id postID editorID post { id title editors { nextToken } labels { nextToken } } editor { id username posts { nextToken } } } } ;Crowfoot
T
12

You should pass your parameters as a second parameter of graphqlOperation. so , check your parentheses
API.graphql(graphqlOperation((deletePostEditor, {input: {id},}))),you have one pair extra parenthesis

below is correct one
API.graphql(graphqlOperation(deletePostEditor, { input: { id } }))

  • first param=deletePostEditor
  • second param={ input: { id } }

tiny mistake, Isn't It?

Torquay answered 2/1, 2020 at 3:48 Comment(2)
I am ashamed of my mistake... I should not turn off eslint or watch the code carefully....Crowfoot
it happened to all of us don't worry:-)Torquay

© 2022 - 2024 — McMap. All rights reserved.