From ab81df7f3d317281a05caec18e2cfd89dc26bc7a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 28 Nov 2023 15:09:04 +0100 Subject: refactor(services): avoid nested fetchers If we use fetchPostsCount inside fetchAllPostsSlugs, we might have problems to test fetchAllPostsSlugs failure. So it is better to let the consumer pass the posts count as an argument. The same applies to thematics and topics. --- .../graphql/fetchers/thematics/fetch-all-thematics-slugs.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/services/graphql/fetchers/thematics/fetch-all-thematics-slugs.ts') diff --git a/src/services/graphql/fetchers/thematics/fetch-all-thematics-slugs.ts b/src/services/graphql/fetchers/thematics/fetch-all-thematics-slugs.ts index 739c009..c44bb6d 100644 --- a/src/services/graphql/fetchers/thematics/fetch-all-thematics-slugs.ts +++ b/src/services/graphql/fetchers/thematics/fetch-all-thematics-slugs.ts @@ -1,6 +1,5 @@ import type { GraphQLNodes, Nullable, SlugNode } from '../../../../types'; import { fetchGraphQL, getGraphQLUrl } from '../../../../utils/helpers'; -import { fetchThematicsCount } from './fetch-thematics-count'; type ThematicsSlugsResponse = { thematics: Nullable>; @@ -17,14 +16,16 @@ const thematicsSlugsQuery = `query ThematicsSlugs($first: Int) { /** * Retrieve the WordPress thematics slugs. * + * @param {number} count - The number of thematics slugs to retrieve. * @returns {Promise} The thematics slugs. */ -export const fetchAllThematicsSlugs = async (): Promise => { - const thematicsCount = await fetchThematicsCount(); +export const fetchAllThematicsSlugs = async ( + count: number +): Promise => { const response = await fetchGraphQL({ query: thematicsSlugsQuery, url: getGraphQLUrl(), - variables: { first: thematicsCount }, + variables: { first: count }, }); if (!response.thematics) -- cgit v1.2.3