@@ -60,14 +60,16 @@ export function itemUpdateQuery (client, id, sort, fn) {
60
60
61
61
// update the newComments field of a nested comment fragment
62
62
export function commentUpdateFragment ( client , id , fn ) {
63
- client . cache . updateFragment ( {
63
+ const result = client . cache . updateFragment ( {
64
64
id : `Item:${ id } ` ,
65
65
fragment : COMMENT_WITH_NEW ,
66
66
fragmentName : 'CommentWithNew'
67
67
} , ( data ) => {
68
68
if ( ! data ) return data
69
69
return fn ( data )
70
70
} )
71
+
72
+ return result
71
73
}
72
74
73
75
function cacheNewComments ( client , rootId , newComments , sort ) {
@@ -83,17 +85,10 @@ function cacheNewComments (client, rootId, newComments, sort) {
83
85
itemUpdateQuery ( client , rootId , sort , ( data ) => mergeNewComment ( data , newComment ) )
84
86
} else {
85
87
// if the comment is a reply, update the parent comment
86
- // but first check if parent exists in cache before attempting update
87
- const parentExists = client . cache . readFragment ( {
88
- id : `Item:${ parentId } ` ,
89
- fragment : COMMENT_WITH_NEW ,
90
- fragmentName : 'CommentWithNew'
91
- } )
88
+ // merge the new comment into the parent comment's newComments field, checking for duplicates
89
+ const result = commentUpdateFragment ( client , parentId , ( data ) => mergeNewComment ( data , newComment ) )
92
90
93
- if ( parentExists ) {
94
- // merge the new comment into the parent comment's newComments field, checking for duplicates
95
- commentUpdateFragment ( client , parentId , ( data ) => mergeNewComment ( data , newComment ) )
96
- } else {
91
+ if ( ! result ) {
97
92
// parent not in cache, queue for retry
98
93
queuedComments . push ( newComment )
99
94
}
0 commit comments