GraphQL错误: Unknown argument 'deleted' on field 'removeFromPostsOnComments'

标签 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

最佳答案

我重现了您的问题。首先,您收到错误消息,因为 deleted 不是 removeFromPostsOnComments 突变的参数的一部分,您还在文档中看到:

enter image description here

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

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

关于GraphQL错误: Unknown argument 'deleted' on field 'removeFromPostsOnComments' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43345776/

相关文章:

node.js - Mongodb graphQL和Feather js通过_id获取数据在某些情况下返回null

scala - 使用 Sangria 创建资源时,将 id 排除在 GraphQL 迁移之外

reactjs - 使用 GraphQL 或 GraphQL 端点生成 schema.json

sql - 防止某个 GraphCool 模型重复

javascript - GraphQL/graphcool - 关系的变异

javascript - 如何在 React 应用程序中处理订阅

graphql - 如何使用 Apollo 客户端按顺序链接两个 GraphQL 查询

c# - 需要帮助在 HotChocolate 过滤器中创建求和聚合操作

node.js - 如何避免在错误响应中将错误集合包装在 Apollo Server V2 的错误对象中

android - 如何在android中解析graph cool service