blob: 8af2757af83e716eede77c4347293a97a2ae5217 (
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
|
import type { GraphQLNodes, Nullable, SlugNode } from '../../../../types';
import { fetchGraphQL, getGraphQLUrl } from '../../../../utils/helpers';
export type TopicsSlugsResponse = {
topics: Nullable<GraphQLNodes<SlugNode>>;
};
const topicsSlugsQuery = `query TopicsSlugs($first: Int) {
topics(first: $first) {
nodes {
slug
}
}
}`;
/**
* Retrieve the WordPress topics slugs.
*
* @param {number} count - The number of topics slugs to retrieve.
* @returns {Promise<string[]>} The topics slugs.
*/
export const fetchAllTopicsSlugs = async (count: number): Promise<string[]> => {
const response = await fetchGraphQL<TopicsSlugsResponse>({
query: topicsSlugsQuery,
url: getGraphQLUrl(),
variables: { first: count },
});
if (!response.topics)
return Promise.reject(new Error('Unable to find the topics slugs.'));
return response.topics.nodes.map((node) => node.slug);
};
|