How to Get Children Categories Using GraphQL

29 views
Skip to first unread message

Lex Medeiros

unread,
May 26, 2022, 9:58:31 PM5/26/22
to dot...@googlegroups.com
Good evening, everyone!

Does anyone know how to get children categories using graphql?

Here is the usual velocity code that does that:

                 #foreach($con in $categories.getChildrenCategoriesByKey("INSERKEY"))
                       
                 ....
                         #end 

Thank you,

Alex

Daniel Silva

unread,
May 27, 2022, 12:29:19 PM5/27/22
to dotCMS User Group
Hello Alex, 

The following query gets a product with its list of categories, in this case only one. This is against demo.dotcms.com

query: 
```
{
  productCollection(query: "+identifier:09841761-aea5-4a1c-a3f3-21e0bc9f7124") {
        title
        category {
            name
        }
    }
}
```

response: 
```
{
    "data": {
        "productCollection": [
            {
                "title": "Quiksilver Men's 3/2mm Syncro Series - Back Zip GBS Wetsuit",
                "category": [
                    {
                        "name": "Water"
                    }
                ]
            }
        ]
    }
}
```

As shown in the query the category field is available as a graphql field, by its variable name, and then you need to select what to show for each cat, in this case only the name. 

Daniel

Lex Medeiros

unread,
May 27, 2022, 12:47:23 PM5/27/22
to dot...@googlegroups.com
Dear Daniel:

Thank you!  This displays the selected category for the contentlet.

What I am looking for to extract are all the children categories that are in a specific category.  Just as I do with this code:


               #foreach($con in $categories.getChildrenCategoriesByKey("INSERKEY"))
                       
                 ....
                         #end 

The reason I need this is because I need to create a filter page with all the category keys so users can search on the category they desire.  Or, is there a way to get the list of the children category of a category field using graphql?

Alex

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/10f466cb-4a25-4795-89f0-7af30a234a94n%40googlegroups.com.

Daniel Silva

unread,
May 31, 2022, 9:51:56 AM5/31/22
to dotCMS User Group
Hello Alex, 

Categories are only available as related to content, as a part of the Content Delivery API, not isolated. 

Daniel

Will Ezell

unread,
May 31, 2022, 9:58:03 AM5/31/22
to dot...@googlegroups.com
@alex, I'll add a feature request for pulling categories via GraphQL



--



382 NE 191st St #92150
Miami, Florida 33179-3899
Main: 
305-900-2001 | Direct: 978.294.9429

Alex

unread,
Jun 5, 2022, 3:27:47 PM6/5/22
to dotCMS User Group
Thank you, Will! It is necessary! 
Reply all
Reply to author
Forward
0 new messages