2017-04-11 48 views
2

所以,我从文章到评论的一对多的关系:GraphQL错误:未知参数“删除”现场“removeFromPostsOnComments”

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! 
 
}

,并希望运行的突变,以及删除帖子和评论之间的连接,尝试将字段'删除,评论,更新为':

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

+0

您的突变在服务器上的外观如何? –

+0

@ Locco0_0如果您的意思是生成的运行突变的输出是什么样子,请参阅我的修正问题。 – TheoG

+0

GraphQL错误表明您没有将已删除的参数添加到服务器上的突变 –

回答

3

我转载了你的问题。首先,你得到错误信息,因为deleted不是的removeFromPostsOnComments -mutation的参数的一部分,你也看到,在文档:

enter image description here

如果你想更新deleted场在Comments类型中,您必须使用updateComments-突变:

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

非常感谢您的澄清。 – TheoG