blob: c44bb6dfc6ba2214bccc052b1184e6da3a873bea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import type { GraphQLNodes, Nullable, SlugNode } from '../../../../types';
import { fetchGraphQL, getGraphQLUrl } from '../../../../utils/helpers';
type ThematicsSlugsResponse = {
thematics: Nullable<GraphQLNodes<SlugNode>>;
};
const thematicsSlugsQuery = `query ThematicsSlugs($first: Int) {
thematics(first: $first) {
nodes {
slug
}
}
}`;
/**
* Retrieve the WordPress thematics slugs.
*
* @param {number} count - The number of thematics slugs to retrieve.
* @returns {Promise<string[]>} The thematics slugs.
*/
export const fetchAllThematicsSlugs = async (
count: number
): Promise<string[]> => {
const response = await fetchGraphQL<ThematicsSlugsResponse>({
query: thematicsSlugsQuery,
url: getGraphQLUrl(),
variables: { first: count },
});
if (!response.thematics)
return Promise.reject(new Error('Unable to find the thematics slugs.'));
return response.thematics.nodes.map((node) => node.slug);
};
|