summaryrefslogtreecommitdiffstats
path: root/src/services/graphql/topics.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/graphql/topics.ts')
-rw-r--r--src/services/graphql/topics.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/services/graphql/topics.ts b/src/services/graphql/topics.ts
new file mode 100644
index 0000000..0f59bad
--- /dev/null
+++ b/src/services/graphql/topics.ts
@@ -0,0 +1,42 @@
+import { RawTopicPreview, TotalItems } from '@ts/types/raw-data';
+import { EdgesResponse, EdgesVars, fetchAPI, getAPIUrl } from './api';
+import { topicsListQuery, totalTopicsQuery } from './topics.query';
+
+/**
+ * Retrieve the total number of topics.
+ *
+ * @returns {Promise<number>} - The topics total number.
+ */
+export const getTotalTopics = async (): Promise<number> => {
+ const response = await fetchAPI<TotalItems, typeof totalTopicsQuery>({
+ api: getAPIUrl(),
+ query: totalTopicsQuery,
+ });
+
+ return response.topics.pageInfo.total;
+};
+
+/**
+ * Retrieve the given number of topics from API.
+ *
+ * @param {EdgesVars} props - An object of GraphQL variables.
+ * @returns {Promise<EdgesResponse<RawTopicPreview>>} The topics data.
+ */
+export const getTopicsPreview = async (
+ props: EdgesVars
+): Promise<EdgesResponse<RawTopicPreview>> => {
+ const response = await fetchAPI<RawTopicPreview, typeof topicsListQuery>({
+ api: getAPIUrl(),
+ query: topicsListQuery,
+ variables: props,
+ });
+
+ return response.topics;
+};
+
+export const getAllTopicsLinks = async () => {
+ const allTopics = [];
+ const initialTopics = await getTopicsPreview({ first: 1 });
+
+ if (!initialTopics.pageInfo.hasNextPage) return initialTopics;
+};