GraphQL错误:字段'removeFromPostsOnComments'上的未知参数'已删除'

时间:2017-04-11 12:21:21

标签: graphql graphcool

所以,我有从帖子到评论的一对多关系:

type Comments {
  createdAt: DateTime!
  deleted: Boolean
  id: ID!
  posts: Posts @relation(name: "PostsOnComments")
  text: String!
  updatedAt: DateTime!
  user: String!
}

type Posts {
  caption: String!
  comments: [Comments!]! @relation(name: "PostsOnComments")
  createdAt: DateTime!
  displaysrc: String!
  id: ID!
  likes: Int
  updatedAt: DateTime!
}

并希望运行一个变异,同时删除帖子和评论之间的连接,尝试将“已删除的评论”字段更新为true:

mutation removeComment ($id: ID!, $cid: ID!, $stateB: Boolean) {
  removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB){
    postsPosts {
      __typename
      id
      comments {
        __typename
        id
        text
        user
        deleted
        posts {
          __typename
          id
        }
      }
    }
  }
}
  
Query Variables

{
  "id": "cj0qkl04vep8k0177tky596og",
  "cid": "cj1de905k8ya201934l84c3id"
}

但是当我运行突变时,我收到以下错误消息:

GraphQL error: Unknown argument 'deleted' on field 'removeFromPostsOnComments' of type 'Mutation'. (line 2, column 74):
  removeFromPostsOnComments(postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB) {

正如向我here解释的那样,只删除了帖子和评论之间的链接,而不是实际的“评论”记录本身。所以我的想法是,由于记录没有删除,为什么我不能更新'已删除'字段?

我希望这样做,以便触发订阅,即监控updated字段'已删除'。

生成的突变输出如下:

  "data": null,
  "errors": [
    {
      "message": "Unknown argument 'deleted' on field 'removeFromPostsOnComments' of type 'Mutation'. (line 2, column 77):\n    removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB){\n                                                                            ^",
      "locations": [
        {
          "line": 2,
          "column": 77
        }
      ]
    }
  ]
}

从图中可以看出,'删除'肯定包含在我的GraphCool架构的'评论'中:

enter image description here

1 个答案:

答案 0 :(得分:3)

我转载了你的问题。首先,您收到错误消息,因为deleted不是removeFromPostsOnComments - 变异参数的一部分,您还会在文档中看到:

enter image description here

如果您要更新deleted类型的Comments字段,则必须使用updateComments - 变种:

mutation {
  updateComments(id: "cj1de905k8ya201934l84c3id", deleted: true) {
    id
  }
}