(
data: PostCommentsData,
)
| 98 | } |
| 99 | |
| 100 | const updateQueryData = ( |
| 101 | data: PostCommentsData, |
| 102 | ): PostCommentsData | undefined => { |
| 103 | const copy = structuredClone(data); |
| 104 | const { edges } = copy.postComments; |
| 105 | |
| 106 | if (!editCommentId) { |
| 107 | const edge = generateCommentEdge(comment); |
| 108 | |
| 109 | if (!parentCommentId) { |
| 110 | edges.unshift(edge); |
| 111 | return copy; |
| 112 | } |
| 113 | |
| 114 | const parent = edges.find(({ node }) => node.id === parentCommentId); |
| 115 | |
| 116 | if (!parent) { |
| 117 | return undefined; |
| 118 | } |
| 119 | |
| 120 | parent.node.children.edges.push(edge); |
| 121 | return copy; |
| 122 | } |
| 123 | |
| 124 | const replies = edges.flatMap(({ node }) => node.children?.edges ?? []); |
| 125 | const edited = [...edges, ...replies].find( |
| 126 | ({ node }) => node.id === editCommentId, |
| 127 | ); |
| 128 | |
| 129 | if (!edited) { |
| 130 | return undefined; |
| 131 | } |
| 132 | |
| 133 | edited.node = { ...comment, children: edited.node.children }; |
| 134 | return copy; |
| 135 | }; |
| 136 | |
| 137 | const forInvalidation: QueryKey[] = []; |
| 138 |
no test coverage detected