-
Notifications
You must be signed in to change notification settings - Fork 355
/
ReplyListViewNewMutation.tsx
54 lines (50 loc) · 1.48 KB
/
ReplyListViewNewMutation.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { ConnectionHandler, Environment, RecordProxy } from "relay-runtime";
import { CoralContext } from "coral-framework/lib/bootstrap";
import {
commitLocalUpdatePromisified,
createMutation,
} from "coral-framework/lib/relay";
import { ShowMoreRepliesEvent } from "coral-stream/events";
interface ReplyListViewNewInput {
commentID: string;
}
const QueueViewNewMutation = createMutation(
"viewNew",
async (
environment: Environment,
input: ReplyListViewNewInput,
{ eventEmitter }: CoralContext
) => {
await commitLocalUpdatePromisified(environment, async store => {
const parentProxy = store.get(input.commentID);
if (!parentProxy) {
return;
}
const connectionKey = "ReplyList_replies";
const filters = { orderBy: "CREATED_AT_ASC" };
const connection = ConnectionHandler.getConnection(
parentProxy,
connectionKey,
filters
);
if (!connection) {
return;
}
const viewNewEdges = connection.getLinkedRecords(
"viewNewEdges"
) as RecordProxy[];
if (!viewNewEdges || viewNewEdges.length === 0) {
return;
}
viewNewEdges.forEach(edge => {
ConnectionHandler.insertEdgeAfter(connection, edge);
});
connection.setLinkedRecords([], "viewNewEdges");
ShowMoreRepliesEvent.emit(eventEmitter, {
commentID: input.commentID,
count: viewNewEdges.length,
});
});
}
);
export default QueueViewNewMutation;