Expand my Community achievements bar.

SOLVED

AEM 6.5 | Graphql query to fetch Tags

Avatar

Level 3

In my custom react application, I wanted to fetch and show one of the Tag values. Wondering if I can do it using Graphql query.

2 Accepted Solutions

Avatar

Correct answer by
Employee Advisor

@Mukesh_Kumar_Co 
If tags are stored on Content Fragment itself, then it can be achieved via following: 
query {
cityList(
filter: {_tags: {_expressions: [{value: "tourism:city-break", _operator: CONTAINS}]}}
){
items {
name,
_tags
}
}
}

Or

 

If these tages are on Content Fragment Metadata, then it can be achieved, via:

{
adventureList {
items {
          _path,
          _metadata {

                stringArrayMetadata {
                               name,
                               value
                }
         }
   }
}
}

You will get all the metadata properties with String Array as Data Type, including cq:tags

View solution in original post

Avatar

Correct answer by
Employee Advisor
5 Replies

Avatar

Correct answer by
Employee Advisor

@Mukesh_Kumar_Co 
If tags are stored on Content Fragment itself, then it can be achieved via following: 
query {
cityList(
filter: {_tags: {_expressions: [{value: "tourism:city-break", _operator: CONTAINS}]}}
){
items {
name,
_tags
}
}
}

Or

 

If these tages are on Content Fragment Metadata, then it can be achieved, via:

{
adventureList {
items {
          _path,
          _metadata {

                stringArrayMetadata {
                               name,
                               value
                }
         }
   }
}
}

You will get all the metadata properties with String Array as Data Type, including cq:tags

Avatar

Level 3

Thanks for your prompt response @krati_garg. Actually, I wanted to fetch the Tag based on the path and their child element only. Wondering if Graphql supports that.

Avatar

Level 3

The JSON of Tags as well as its child Tags are the desired result. Below is the JSON response for a single Tag(without child) I'm getting from https://{$HOSTNAME}/content/cq:tags/{$TAG_PATH}.json

 

{"jcr:primaryType":"cq:Tag","jcr:mixinTypes":["rep:AccessControllable"],"jcr:createdBy":"admin","jcr:title":"Solar","jcr:created":"Fri Nov 04 2022 16:01:29 GMT+0000","jcr:description":"","sling:resourceType":"cq/tagging/components/tag"}

Wondering if there is any option to achieve this.

Avatar

Correct answer by
Employee Advisor