Graphql query to return tag details with content fragment data | Community
Skip to main content
Mukesh_Kumar_Co
New Participant
December 9, 2022
Solved

Graphql query to return tag details with content fragment data

  • December 9, 2022
  • 2 replies
  • 1150 views

Hi,

 

In my content fragment model, there is a Tags type field. My Graphql query result returns only the full tag path including the namespace. I need the title of the tag field as well. I don't see a way to retrieve the title. Wondering if I'm missing something?

 

Thanks.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by nitesh_kumar-1
Currently, it only returns TagID. The same field is also used as a filter in the Graphql Query.

 

Another approach, in this case, could be to fetch tag data by tag path, once you fetch the TagID from the GraphQL response

https://{$HOSTNAME}/content/cq:tags/{$TAG_PATH}.json

 

For example, tagID returned in Graphql response:-
"tags": [
"wknd-shared:region/emea"
]
 
Now the tag path can be formed like this
https://{$HOSTNAME}/content/cq:tags/wknd-shared/region/emea.json
 
it returns
{
"jcr:created": "Thu Jul 07 2022 10:42:40 GMT+0000",
"jcr:createdBy": "admin",
"sling:resourceType": "cq/tagging/components/tag",
"jcr:title": "EMEA",
"jcr:description": "Europe, Middle East and Africa",
"jcr:primaryType": "cq:Tag"
}

 

This would return the title and other metadata related to the Tag.

 

Hope this helps.

 

Regards,
Nitesh

2 replies

krati_garg
Employee
December 9, 2022

@mukesh_kumar_co 

The approach suggested by @nitesh_kumar-1 above, looks simple and straight. 

 

However, if you want to fetch the titles in a single GraphQL query, you might have to do some customization on the Schema tag field, so that it saves the titles of the selected tags in another custom property, which can then be called from single GraphQL Query:

{
adventureList {
items {
_path,
_metadata {

stringArrayMetadata {
name,
value
}

}
}
}
}

nitesh_kumar-1
nitesh_kumar-1Accepted solution
Employee
December 9, 2022
Currently, it only returns TagID. The same field is also used as a filter in the Graphql Query.

 

Another approach, in this case, could be to fetch tag data by tag path, once you fetch the TagID from the GraphQL response

https://{$HOSTNAME}/content/cq:tags/{$TAG_PATH}.json

 

For example, tagID returned in Graphql response:-
"tags": [
"wknd-shared:region/emea"
]
 
Now the tag path can be formed like this
https://{$HOSTNAME}/content/cq:tags/wknd-shared/region/emea.json
 
it returns
{
"jcr:created": "Thu Jul 07 2022 10:42:40 GMT+0000",
"jcr:createdBy": "admin",
"sling:resourceType": "cq/tagging/components/tag",
"jcr:title": "EMEA",
"jcr:description": "Europe, Middle East and Africa",
"jcr:primaryType": "cq:Tag"
}

 

This would return the title and other metadata related to the Tag.

 

Hope this helps.

 

Regards,
Nitesh