import { gql, GraphQLClient } from "graphql-request"; import { getBaseUrl } from "./gr-client"; const CategoriesQuery = gql` query Categories { settingCategories { page { id title slug } } } `; export type CategoryPage = { id: string; title: string; slug: string; }; export type SettingCategory = { page: CategoryPage; }; export type CategoriesData = { settingCategories: SettingCategory[]; }; export async function fetchCategories(jwt?: string): Promise { const client = new GraphQLClient(getBaseUrl()); if (jwt) { client.setHeader('Authorization', `Bearer ${jwt}`); } try { const response: any = await client.request(CategoriesQuery); if (response?.settingCategories) { return response; } return null; } catch (error) { console.error('Failed to fetch categories:', error); return null; } }