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

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

我尝试在 api doc("https://aws-amplify.github.io/docs/cli-toolchain/graphql?sdk=js") 上使用示例架构,如下面的多对多连接

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"])
}

我创建了所有项目,然后尝试删除它们,但我失败了,尤其是在 PostEditor 上。

有一个删除 PostEditor 的突变,所以我像下面这样称呼它

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

失败并显示以下错误消息。

错误:无效的 AST 节点:{"input":"b2f7064c-af32-49cd-8c87-*******"}

我想我提供了正确的 ID。我在查询时检查了它。

您应该将您的参数作为 graphqlOperation 的第二个参数传递。所以,检查你的括号
API.graphql(graphqlOperation((deletePostEditor, {input: {id},}))),你多了一对括号

下面是正确的
API.graphql(graphqlOperation(deletePostEditor, { input: { id } }))

  • 第一个参数=deletePostEditor
  • 第二个参数={输入:{id}}

小错误,不是吗?