45 lines
937 B
TypeScript
45 lines
937 B
TypeScript
import { fetchGraphQL } from '@lib/graphql-client.js';
|
|
|
|
|
|
//кэширование
|
|
import { cache } from '@lib/cache/manager.js';
|
|
import { CACHE_TTL } from '@lib/cache/cache-ttl';
|
|
|
|
export interface Category {
|
|
id: string;
|
|
databaseId: number;
|
|
name: string;
|
|
slug: string;
|
|
description: string;
|
|
count: number;
|
|
parentId?: number | null;
|
|
}
|
|
|
|
export async function getCategory(slug: string): Promise<Category | null> {
|
|
const cacheKey = `category:${slug}`;
|
|
|
|
return await cache.wrap(
|
|
cacheKey,
|
|
async () => {
|
|
const query = `
|
|
query GetCategory($slug: ID!) {
|
|
category(id: $slug, idType: SLUG) {
|
|
id
|
|
databaseId
|
|
name
|
|
slug
|
|
description
|
|
count
|
|
parentId
|
|
}
|
|
}
|
|
`;
|
|
|
|
const data = await fetchGraphQL(query, { slug });
|
|
return data?.category || null;
|
|
},
|
|
{ ttl: CACHE_TTL.TAXONOMY }
|
|
);
|
|
}
|
|
|