user
04/27/2017, 8:29 AMhttps://prisma.slack.com/files/U4KKMFVK2/F557PGTL3/no_websocket_connection_made.jpg▾
artyom
04/27/2017, 8:33 AMhardys
04/27/2017, 8:51 AMsamuell
04/27/2017, 8:52 AMartyom
04/27/2017, 8:54 AMsamuell
04/27/2017, 9:00 AMuser
04/27/2017, 9:23 AMhttps://prisma.slack.com/files/U4KKMFVK2/F557PGTL3/no_websocket_connection_made.jpg▾
user
04/27/2017, 9:35 AMhttps://prisma.slack.com/files/U4KKMFVK2/F557PGTL3/no_websocket_connection_made.jpg▾
export const Subscription_Add_Delete_Comment_Query = gql`
subscription CreateDeleteComment {
Comments(
filter: {
mutation_in: [CREATED, DELETED]
}
) {
node {
id
text
user
deleted
posts {
id
}
}
}
}
`;
user
04/27/2017, 9:47 AMhttps://prisma.slack.com/files/U54PXSN04/F557HPF1R/graph.gif▾
user
04/27/2017, 10:25 AMhttps://prisma.slack.com/files/U4KKMFVK2/F557PGTL3/no_websocket_connection_made.jpg▾
nish
04/27/2017, 10:57 AMartyom
04/27/2017, 11:25 AMrichashby
04/27/2017, 11:30 AMdanielvdm
04/27/2017, 11:32 AMuser
04/27/2017, 11:36 AMhttps://prisma.slack.com/files/U4KKMFVK2/F557PGTL3/no_websocket_connection_made.jpg▾
artyom
04/27/2017, 11:56 AMtheom
04/27/2017, 11:57 AMuser
04/27/2017, 11:58 AMhttps://prisma.slack.com/files/U4KKMFVK2/F566NTPPG/initial_websocket_connection.jpg▾
Frames
and screenshot that onetheom
04/27/2017, 12:05 PMuser
04/27/2017, 12:22 PMhttps://prisma.slack.com/files/U4KKMFVK2/F5674LFAB/websocket_frames.jpg▾
data
event, so the subscription works 🙂 Now we need to find out why the callback in apollo is not calledsdubois
04/27/2017, 12:26 PMuser
04/27/2017, 12:26 PMhttps://prisma.slack.com/files/U4KKMFVK2/F5674LFAB/websocket_frames.jpg▾
updateQuery
you currently return the previousState
. Actually you need to merge the new data into the previous state and return that new merged object.sdubois
04/27/2017, 12:27 PMuser
04/27/2017, 12:29 PMhttps://prisma.slack.com/files/U2HEKAQ79/F55CRB21G/screen_shot_2017-04-27_at_15.25.41.png▾
user
04/27/2017, 12:36 PMhttps://prisma.slack.com/files/U4KKMFVK2/F5674LFAB/websocket_frames.jpg▾
isDuplicateComment(newComment, existingComments) {
let duplicateComment = false;
existingComments.forEach((comment) => {
if (newComment.id !== null && newComment.id === comment.id) {
duplicateComment = true;
}
});
console.log('duplicateComment = ', duplicateComment);
return duplicateComment;
},
subscribe() {
const postIndexID = this.props.postIndexID;
return this.subscriptionObserver = this.props.data.subscribeToMore({
document: Subscription_Add_Delete_Comment_Query,
updateQuery: (previousState, {subscriptionData}) => {
// The mutations allways update the Root_Tree, so the newComment will already exist in previousState.
// So you just need to return the previousState as is
console.log('previousState = ', previousState);
console.log('subscriptionData = ', subscriptionData);
// Ascertain whether the mutation fired was created or deleted
if (subscriptionData.data.Comments.mutation === 'CREATED') {
// Ascertain whether the current record has already been added to the ROOT_TREE.
// If so, just return previousState as is.
const newComment = subscriptionData.data.Comments.node;
if (this.isDuplicateComment(newComment, previousState.allPostses[postIndexID].comments)) {
return previousState;
}else {
// const Comments = previousState.allPostses[postIndexID].comments.concat([newComment]); // If adding a new comment to Root_Query
// return Comments;
}
} else if (subscriptionData.data.Comments.mutation === 'DELETED') {
return {
allPostses: previousState.allPostses
}
}
},
onError: (err) => console.error(err),
});
},
My mutations are as follows:
export const Add_Comment_Mutation = gql`
mutation createComment ($id: ID, $textVal: String!, $userVal: String!) {
createComments (postsId: $id, text: $textVal, user: $userVal){
__typename
id
text
user
deleted
posts {
__typename
id
}
}
}
`;
export const Remove_Comment_Mutation = gql`
mutation removeComment ($id: ID!, $cid: ID!) {
removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid) {
postsPosts {
__typename
id
comments {
__typename
id
text
user
deleted
posts {
__typename
id
}
}
}
}
deleteComments(id: $cid) {
id
}
}
`;
sdubois
04/27/2017, 12:40 PMuser
04/27/2017, 12:40 PMhttps://prisma.slack.com/files/U4KKMFVK2/F5674LFAB/websocket_frames.jpg▾
user
04/27/2017, 1:18 PMhttps://prisma.slack.com/files/U4KKMFVK2/F5674LFAB/websocket_frames.jpg▾
That means: You have to check if THIS client executed the mutation, if not, apply the changes that come through the subscription
Ok, so this is the part that I'm confused about. Can you show me how this is done?user
04/27/2017, 1:45 PMhttps://prisma.slack.com/files/U4KKMFVK2/F5674LFAB/websocket_frames.jpg▾
user
04/27/2017, 1:51 PMhttps://prisma.slack.com/files/U4KKMFVK2/F5674LFAB/websocket_frames.jpg▾