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.
Solved! Go to Solution.
Views
Replies
Total Likes
@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
Views
Replies
Total Likes
You can retrieve child tags of a given tag via:
http://localhost:4502/content/cq:tags/we-retail/activity.1.json
OR
For Children at 1 level down- https://{$HOSTNAME}/content/cq:tags/{$TAG_PATH}.1.json
For Children till 2 level down
https://{$HOSTNAME}/content/cq:tags/{$TAG_PATH}.2.json
@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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
can you give an example of the expected response @Mukesh_Kumar_Co
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.
Views
Replies
Total Likes
You can retrieve child tags of a given tag via:
http://localhost:4502/content/cq:tags/we-retail/activity.1.json
OR
For Children at 1 level down- https://{$HOSTNAME}/content/cq:tags/{$TAG_PATH}.1.json
For Children till 2 level down
https://{$HOSTNAME}/content/cq:tags/{$TAG_PATH}.2.json
Views
Likes
Replies