【问题标题】:GraphQL error: Unknown argument 'deleted' on field 'removeFromPostsOnComments'GraphQL 错误:字段“removeFromPostsOnComments”上的未知参数“已删除”
【发布时间】:2017-09-06 19:57:45
【问题描述】:

所以,我从 Posts 到 cmets 是一对多的关系:

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 向我解释的那样,仅删除了帖子和 cmets 之间的链接,而不是实际的“评论”记录本身。所以我的想法是,由于记录没有被删除,为什么我不能更新“已删除”字段?

我希望这样做以触发订阅,该订阅正在监视 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 架构中:

【问题讨论】:

  • 你的变异在服务器上是什么样子的?
  • @Locco0_0 如果您的意思是运行突变生成的输出是什么样的,请查看我修改后的问题。
  • GraphQL 错误表明您没有将已删除的参数添加到服务器上的突变中
  • @Locco0_0 从附图中可以看出,请参阅修改后的问题,“已删除”肯定已添加到我的 GraphCool 架构的“评论”部分。可能是一个错误?

标签: graphql graphcool


【解决方案1】:

我复制了您的问题。首先,您会收到错误消息,因为deleted 不是removeFromPostsOnComments-mutation 的参数的一部分,您还可以在文档中看到:

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

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

【讨论】:

    猜你喜欢
    • 2017-02-03
    • 2019-07-23
    • 2020-10-26
    • 2017-07-13
    • 2016-03-13
    • 2019-09-16
    • 2020-05-18
    • 2020-02-18
    • 1970-01-01
    相关资源
    最近更新 更多