Files
profile-front/src/lib/api/menu.ts

71 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-12-11 01:12:45 +03:00
import { fetchGraphQL } from './graphql-client.js';
2025-12-13 23:29:25 +03:00
interface MenuItemNode {
uri: string;
url: string;
order: number;
label: string;
}
2025-12-11 01:12:45 +03:00
2025-12-13 23:29:25 +03:00
interface MenuNode {
name: string;
menuItems: {
nodes: MenuItemNode[];
};
}
2025-12-11 01:12:45 +03:00
2025-12-13 23:29:25 +03:00
interface MenusResponse {
menus: {
nodes: MenuNode[];
};
}
/**
* Get navigation menu from WordPress
*/
export async function navQuery(): Promise<MenusResponse> {
try {
const query = `{
menus(where: {location: PRIMARY}) {
nodes {
name
menuItems {
nodes {
uri
url
order
label
}
2025-12-11 01:12:45 +03:00
}
}
}
2025-12-13 23:29:25 +03:00
}`;
2025-12-11 01:12:45 +03:00
2025-12-13 23:29:25 +03:00
return await executeQuery<MenusResponse>(query, {}, "navigation");
} catch (error) {
log.error("Error fetching nav: " + error);
// Return fallback data for development
return {
menus: {
nodes: [
{
name: "Primary",
menuItems: {
nodes: [
{ uri: "/", url: "/", order: 1, label: "Home" },
{ uri: "/about/", url: "/about/", order: 2, label: "About" },
{
uri: "/contact/",
url: "/contact/",
order: 3,
label: "Contact",
},
],
},
},
],
},
};
}
2025-12-11 01:12:45 +03:00
}