mirror of
https://github.com/wassname/talk.git
synced 2026-07-09 16:26:30 +08:00
[next] Implement Comment History Pagination (#2008)
* refactor: profile * feat: add pagination to comment history * feat: add getMeSourceID helper * feat: update profile in CreateCommentMutation * fix: clear query response cache on mutation * test: add integration tests for profile * test: add unit tests
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { Environment, ROOT_ID } from "relay-runtime";
|
||||
import { Environment } from "relay-runtime";
|
||||
|
||||
import getMeSourceID from "./getMeSourceID";
|
||||
|
||||
export default function getMe(environment: Environment) {
|
||||
const source = environment.getStore().getSource();
|
||||
const root = source.get(ROOT_ID)!;
|
||||
if (!root.me) {
|
||||
const meID = getMeSourceID(environment);
|
||||
if (!meID) {
|
||||
return null;
|
||||
}
|
||||
const meID = root.me.__ref;
|
||||
return source.get(meID)!;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Environment, ROOT_ID } from "relay-runtime";
|
||||
|
||||
export default function getMeSourceID(environment: Environment): string | null {
|
||||
const source = environment.getStore().getSource();
|
||||
const root = source.get(ROOT_ID)!;
|
||||
if (!root.me) {
|
||||
return null;
|
||||
}
|
||||
return root.me.__ref;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export { default as getMe } from "./getMe";
|
||||
export { default as getMeSourceID } from "./getMeSourceID";
|
||||
export { default as getURLWithCommentID } from "./getURLWithCommentID";
|
||||
export { default as urls } from "./urls";
|
||||
|
||||
@@ -19,6 +19,7 @@ export default function createNetwork(tokenGetter: TokenGetter) {
|
||||
cacheMiddleware({
|
||||
size: 100, // max 100 requests
|
||||
ttl: 900000, // 15 minutes
|
||||
clearOnMutation: true,
|
||||
}),
|
||||
urlMiddleware({
|
||||
url: req => Promise.resolve(graphqlURL),
|
||||
|
||||
@@ -28,7 +28,10 @@ export function denormalizeComments(commentList: any[]) {
|
||||
export function denormalizeAsset(asset: any) {
|
||||
const commentNodes =
|
||||
(asset.comments &&
|
||||
asset.comments.edges.map((edge: any) => denormalizeComment(edge))) ||
|
||||
asset.comments.edges.map((edge: any) => ({
|
||||
...edge,
|
||||
node: denormalizeComment(edge.node),
|
||||
}))) ||
|
||||
[];
|
||||
const commentsPageInfo = (asset.comments && asset.comments.pageInfo) || {
|
||||
endCursor: null,
|
||||
|
||||
Reference in New Issue
Block a user