From 06ea295857e508a830669cb402d2156204309b1e Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 13 May 2022 16:28:06 +0200 Subject: chore: add blog page widgets --- src/services/graphql/thematics.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/services/graphql/thematics.ts (limited to 'src/services/graphql/thematics.ts') diff --git a/src/services/graphql/thematics.ts b/src/services/graphql/thematics.ts new file mode 100644 index 0000000..7003e08 --- /dev/null +++ b/src/services/graphql/thematics.ts @@ -0,0 +1,34 @@ +import { RawThematicPreview, TotalItems } from '@ts/types/raw-data'; +import { EdgesResponse, EdgesVars, fetchAPI, getAPIUrl } from './api'; +import { thematicsListQuery, totalThematicsQuery } from './thematics.query'; + +/** + * Retrieve the total number of thematics. + * + * @returns {Promise} - The thematics total number. + */ +export const getTotalThematics = async (): Promise => { + const response = await fetchAPI({ + api: getAPIUrl(), + query: totalThematicsQuery, + }); + + return response.thematics.pageInfo.total; +}; + +/** + * Retrieve the given number of thematics from API. + * + * @param {EdgesVars} props - An object of GraphQL variables. + * @returns {Promise>} The thematics data. + */ +export const getThematicsPreview = async ( + props: EdgesVars +): Promise> => { + const response = await fetchAPI< + RawThematicPreview, + typeof thematicsListQuery + >({ api: getAPIUrl(), query: thematicsListQuery, variables: props }); + + return response.thematics; +}; -- cgit v1.2.3