so, i'm testing subscriptions on graphcool , appreciate clarification on how work.
i have 1 many relationship posts on comments:
schema
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! }
the subscription run in graphcool follows:
subscription createddeletedcomments { comments( filter: { mutation_in: [created, deleted] } ) { mutation node { id user text } } }
if run following in react app, created notification fired:
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, })
but if run following, no deleted notification fired:
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, })
what overlooking here?
with subscription
subscription createddeletedcomments { comments( filter: { mutation_in: [created, deleted] } ) { mutation node { id user text } } }
you subscribing comment nodes being created or deleted. however, mutation removefrompostsoncomments
, not deleting comment nodes. instead, deleting connection between post , comment.
you can adjust mutation request delete comment entirely instead of disconnecting post:
return this.props.client.mutate({ mutation: gql` mutation removecomment ($cid: id!) { deletecomment(id: $cid) { id } } `, variables: { "cid": commentid }, // forcefetch: true, })
if don't want delete comment entirely still want hide in app, have boolean field deleted
acts soft deletion marker.
then subscribe updated
comments instead of deleted
comments , check if field deleted
updated. refer the docs more information on how updatedfields
.
subscriptions relations part of our roadmap.
Comments
Post a Comment