2
因此,我正在測試Graphcool上的訂閱,並希望對它們的工作原理做一些說明。GraphQL:當突變運行時不會觸發訂閱
我從帖子上的評論一個一對多的關係:
架構
type Posts {
caption: String!
comments: [Comments!]! @relation(name: "PostsOnComments")
createdAt: DateTime!
displaysrc: String!
id: ID!
likes: Int
updatedAt: DateTime!
}
type Comments {
createdAt: DateTime!
id: ID!
posts: Posts @relation(name: "PostsOnComments")
text: String!
updatedAt: DateTime!
user: String!
}
我Graphcool運行認購如下:
subscription CreatedDeletedComments {
\t Comments(
filter: {
mutation_in: [CREATED, DELETED]
}
) {
mutation
node {
id
user
text
}
}
}
如果我跑在我作出反應的應用程序下面,創建的通知被解僱:
return this.props.client.mutate({
mutation: gql`
mutation createComment ($id: ID, $textVal: String!, $userVal: String!) {
createComments (postsId: $id, text: $textVal, user: $userVal){
id
text
user
}
}
`,
variables: {
"id": postID,
"textVal": textVal,
"userVal": userVal
},
// forceFetch: true,
})
但是,如果我運行下面,沒有刪除的通知被觸發:
return this.props.client.mutate({
mutation: gql`
mutation removeComment ($id: ID!, $cid: ID!) {
removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid){
postsPosts {
id
displaysrc
likes
comments {
id
text
user
}
}
}
}
`,
variables: {
"id": postID,
"cid": commentID
},
// forceFetch: true,
})
我在這裏忽略了什麼?
完美。我使用deleteComments唯一的問題是與我的用戶界面,被動緩存相關,而不是更新以反映更改。因爲我的root_query(如Apollo devTools中描述的),我如何重構updateQueries(請參閱我更新的問題)以處理'this.props.client.mutate'(我是從onClick事件觸發的)是'allPostses'? – TheoG
你能爲此發佈一個單獨的問題嗎?一般來說,推薦使用'update',而不是現在使用'updateQueries'。 – marktani
當然。提交了新問題。 – TheoG