2017-04-11 22 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