@apollo/client/utilities#Reference TypeScript Examples
The following examples show how to use
@apollo/client/utilities#Reference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: paginationHandler.ts From lexicon with MIT License | 6 votes |
export function prependAppendPagination<T = Reference>(
keyArgs: KeyArgs = [],
): FieldPolicy<Array<T>> {
return {
keyArgs,
merge: (existing: any, incoming: any) => {
if (
!existing ||
!incoming ||
existing.length === 0 ||
incoming.length === 0
) {
return incoming || existing || null;
}
if (
JSON.stringify(existing[existing.length - 1]) <
JSON.stringify(incoming[incoming.length - 1])
) {
return handleDuplicateRef(existing, incoming);
} else {
// Prepending data will trigger data reindexing.
// There's an issue with data reindexing inside a FlatList,
// because the cursor position is not "held" at the current post.
return handleDuplicateRef(incoming, existing);
}
},
};
}
Example #2
Source File: paginationHandler.ts From lexicon with MIT License | 5 votes |
export function replaceDataPagination<T = Reference>(
keyArgs: KeyArgs = [],
): FieldPolicy<Array<T>> {
return {
keyArgs,
merge: (existing: any, incoming: any) => incoming || existing || null,
};
}
Example #3
Source File: paginationHandler.ts From lexicon with MIT License | 5 votes |
export function appendPagination<T = Reference>(
keyArgs: KeyArgs = [],
screen: 'HOME' | 'SEARCH' | 'MESSAGE_DETAIL' | 'NOTIFICATIONS',
): FieldPolicy<Array<T>> {
return {
keyArgs,
merge: (existing: any, incoming: any, { args }) => {
if (!existing || !incoming) {
return existing || incoming || null;
}
let page;
switch (screen) {
case 'HOME':
page = args?.page || 0;
incoming.users = handleDuplicateRef(existing.users, incoming.users);
if (page > 0) {
incoming.topicList.topics = handleDuplicateRef(
existing.topicList.topics,
incoming.topicList.topics,
);
} else {
incoming.topicList.topics = handleDuplicateRef(
incoming.topicList.topics,
existing.topicList.topics,
);
}
break;
case 'SEARCH':
page = args?.page || 1;
if (page > 1) {
incoming.posts = handleDuplicateRef(existing.posts, incoming.posts);
incoming.topics = handleDuplicateRef(
existing.topics,
incoming.topics,
);
}
break;
case 'MESSAGE_DETAIL':
page = args?.page || 0;
if (page >= 0) {
incoming.topicList.topics = handleDuplicateRef(
incoming.topicList.topics,
existing.topicList.topics,
);
incoming.users = handleDuplicateRef(incoming.users, existing.users);
}
break;
case 'NOTIFICATIONS':
incoming.notifications = handleDuplicateRef(
existing.notifications,
incoming.notifications,
);
break;
}
return incoming;
},
};
}