0

I have created a custom module for megamenu. I have created the graphQL query for that also. The query returns the correct result for level 0. How can I get the tree structure? Here is my graphql schema.

    type Query {
    menus(
       menuType: String @doc(description: "Defines the filter to use for searching menus")
    ): Menus @resolver(class: "Test\\MegamenuGraphQl\\Model\\Resolver\\Megamenu") @doc(description: "Retrieves the menus based on filter if filter applied.")
}

type Menus @doc(description: "The collection of menus .") {
    items: [Menu] @doc(description: "An array of menuss")
    
}

type Menu @doc(description: "Contains details about each of the menu.") {
    Type: String @doc(description: "The Menu Type")
    menu_items: [MenuItems] @doc(description: "The details of menu")
}

type MenuItems @doc(description: "Contains details about each of the menu.") {
    menu_id: ID @doc(description: "The menu Id")
    title: String @doc(description: "The menu title")
    menu_type:String @doc(description: "The menu type")
    link: String @doc(description: "The menu link")
    image: String @doc(description: "The menu image")
    position:ID @doc(description: "The menu position")
    parent_id: ID @doc(description: "The parent menu id")
    parent_name: String @doc(description: "The parent menu name")
    children: [MenuItems] @doc(description: "The details of menu")
}

1 Answer 1

0

Magento have default API for tree menu.

{
  categories(
    filters: { parent_id: { in: ["2"] } }
    pageSize: 10
    currentPage: 1
  ) {
    total_count
    items {
      uid
      level
      name
      path
      url_key
      children_count
      children {
        uid
        level
        name
        path
        children_count
        children {
          uid
          level
          name
          path
        }
      }
    }
    page_info {
      current_page
      page_size
      total_pages
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.