Need to get details from hierarchy level data

Hello,

I create new Category type DQL schema as below. Need to set category as hierarchy level

type Category {
  name: String! @id @search(by: [regexp])
  position: Int @default(add: { value: 0})
  parent: Category
  subCategories: [Category] @hasInverse(field: parent)
}

When try to get details of child category using graphql query as below

{
  queryCategory {
    name
    position
    parent(filter: {name: {eq:"Parts"}}) {
      name
    }
  }
}

It’s return all categories data as below

{
  "data": {
    "queryCategory": [
      {
        "name": "Parts",
        "position": 1,
        "parent": null
      },
      {
        "name": "Mobile Parts",
        "position": 9,
        "parent": {
          "name": "Parts"
        }
      }
    ]
  },
}

Please help for that anything wrong with schema or query?

Check out @cascade Directive - GraphQL

1 Like

Using cascade can get child category details but how can i get all root level categories which have no parents?
I tried below which is not working.

{
  querycategory {
    name
    position
    parent(filter: {name: {eq: null}}) {
      name
    }
  }
}

queryCategory(filter: { not: { has: [parent] } })

I’d recommend taking the GraphQL tour if you haven’t already, covers all this and more: Welcome | Graphqlintro | Dgraph Tour

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.