因此,我从帖子到评论之间存在一对多关系:
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 架构的“评论”中:
最佳答案
我重现了您的问题。首先,您收到错误消息,因为 deleted
不是 removeFromPostsOnComments
突变的参数的一部分,您还在文档中看到:
如果您想更新 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/