错误:无效的 AST 节点:{"input":"** } 在 graphql 突变上(放大客户端)

Min*_*eSu 4 amplifyjs graphql aws-amplify

我尝试在 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"])
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

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

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

Ale*_*lex 9

您应该将您的参数作为graphqlOperation. 所以,检查你的括号
API.graphql(graphqlOperation((deletePostEditor, {input: {id},}))),你有一对额外的括号

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

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

小错误,不是吗?

  • 这发生在我们所有人身上,不用担心:-) (3认同)