strapi-plugin-navigation
strapi-plugin-navigation copied to clipboard
Strapi v5: A way of fetching all navigations with GraphQL
I would like to ask if it is currently possible to fetch all navigations at once using GraphQL?
If not, I would like to request this feature, as it would be very useful in my use case.
Use Case: In my page layout, I need to fetch multiple menus, such as the main navigation menu and the footer menus. Instead of fetching each menu individually, I would prefer to fetch all menus in a single GraphQL query and then utilize them in the appropriate sections by using their slugs.
This would simplify the data-fetching process and improve efficiency.
Thank you for considering this request!
GQL does not support it yet.
Would you like to fetch all with nested items ? Or just flat structure to preprocess on the FE?
It would be great to handle both cases, e.g. via the type parameter. In my case, I use a flat structure for the mobile version and a tree structure for the desktop version
If I had to choose one, I would prefer to receive an API response with nested elements.
@michsko544
in graphql you can do that natively, maybe this can fit to you
#import ./fragments/NavigationItem.gql
query GetNavigation($locale: I18NLocaleCode) {
footer: renderNavigation(locale: $locale, navigationIdOrSlug: "footer-navigation", type: TREE) {
...NavigationItem
}
navigation: renderNavigation(locale: $locale, navigationIdOrSlug: "main-navigation", type: TREE) {
...NavigationItem
}
mobile: renderNavigation(locale: $locale, navigationIdOrSlug: "mobile-navigation", type: TREE) {
...NavigationItem
}
}
@liqueflies That's amazing! I didn't know you could use a similar query multiple times and assign it to a variable. Thank you for the tip! @cyp3rius Perhaps we can go ahead and close this issue now?
I think so ;)