diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-13 16:28:06 +0200 | 
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-13 16:28:06 +0200 | 
| commit | 06ea295857e508a830669cb402d2156204309b1e (patch) | |
| tree | 87db074b639c6bf1cd3b8bbe27858662196dc6b9 /src/services/graphql/topics.ts | |
| parent | dab72bb270ee2ee47a0b472d5e9e240cba7cbf0f (diff) | |
chore: add blog page widgets
Diffstat (limited to 'src/services/graphql/topics.ts')
| -rw-r--r-- | src/services/graphql/topics.ts | 42 | 
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; +}; | 
