错误:graphql突变上无效的AST节点:{“ input”:“ **}(放大clinet)

时间:2019-12-29 02:10:04

标签: graphql aws-amplify amplifyjs

我尝试在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。我在查询时检查过。

1 个答案:

答案 0 :(得分:3)

您应该将参数作为graphqlOperation的第二个参数传递。因此,请检查您的括号
API.graphql(graphqlOperation((deletePostEditor, {input: {id},}))),括号中要有一对

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

  • first param = deletePostEditor
  • second param = {输入:{id}}

微小的错误,不是吗?