aboutsummaryrefslogtreecommitdiffstats
path: root/src/services/graphql/articles.ts
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-20 15:37:08 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-20 15:37:08 +0200
commitf4c7ab4e306d2f04324853e67032d370abd65d0c (patch)
tree2c7d1ad467d6c52bc134202f0d33f7524f9056fa /src/services/graphql/articles.ts
parentbbd63400f94b43fde04449e0c71d14763d893e6a (diff)
chore: handle blog pagination when JS is disabled
Diffstat (limited to 'src/services/graphql/articles.ts')
-rw-r--r--src/services/graphql/articles.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/services/graphql/articles.ts b/src/services/graphql/articles.ts
index 41052c4..f130872 100644
--- a/src/services/graphql/articles.ts
+++ b/src/services/graphql/articles.ts
@@ -7,10 +7,18 @@ import {
import { getAuthorFromRawData } from '@utils/helpers/author';
import { getImageFromRawData } from '@utils/helpers/images';
import { getPageLinkFromRawData } from '@utils/helpers/pages';
-import { EdgesResponse, EdgesVars, fetchAPI, getAPIUrl, PageInfo } from './api';
+import {
+ EdgesResponse,
+ EdgesVars,
+ EndCursor,
+ fetchAPI,
+ getAPIUrl,
+ PageInfo,
+} from './api';
import {
articleBySlugQuery,
articlesCardQuery,
+ articlesEndCursor,
articlesQuery,
articlesSlugQuery,
totalArticlesQuery,
@@ -173,3 +181,21 @@ export const getAllArticlesSlugs = async (): Promise<string[]> => {
return response.posts.edges.map((edge) => edge.node.slug);
};
+
+/**
+ * Retrieve the last cursor.
+ *
+ * @param {EdgesVars} props - An object of GraphQL variables.
+ * @returns {Promise<string>} - The end cursor.
+ */
+export const getArticlesEndCursor = async (
+ props: EdgesVars
+): Promise<string> => {
+ const response = await fetchAPI<EndCursor, typeof articlesEndCursor>({
+ api: getAPIUrl(),
+ query: articlesEndCursor,
+ variables: { ...props },
+ });
+
+ return response.posts.pageInfo.endCursor;
+};