async-postgres icon indicating copy to clipboard operation
async-postgres copied to clipboard

Getting all categories as a tree.

Open LiamKarlMitchell opened this issue 4 years ago • 0 comments

Possible to do this with graphql.

Ok not strictly rest api? But wonder if it is of use?

https://magentorooturl/graphql

{
  category(id: 2) {
    products {
      total_count
      page_info {
        current_page
        page_size
      }
    }
    children_count
    children {
      id
      level
      name
      path
      children {
        id
        level
        name
        path
        children {
          id
          level
          name
          path
          children {
            id
            level
            name
            path
          }
        }
      }
    }
  }
}
{
  category(id: ${categoryId}) {
    id
    name
    children {
      id
      name
      children {
        id
        name
        children {
          id
          name
        }
      }
    }
  }
}

Note: Does not return deactivated categorys!

Can try it in Altair GraphQL Client browser extension. chrome-extension://flnheeellpciglgpaodhkhmapeljopja/index.html

Vue Storefront seems to do it a different way. https://github.com/DivanteLtd/vue-storefront/blob/master/core/pages/Category.js

LiamKarlMitchell avatar May 19 '20 05:05 LiamKarlMitchell