Hi all,
I've the need to query a set of fragments and order the results by the value of a specific calendar metadata with name "cq:lastModified" or "cq:lastModified".
I found a way to extract the metadata values with this query:
query {
myFragmentList {
items {
_metadata {
calendarMetadata {
name
value
}
}
}
}
}
that gives me this result
...
"items": [
{
"_metadata": {
"calendarMetadata": [
{
"name": "jcr:created",
"value": "2023-10-19T15:24:21.482Z"
},
{
"name": "cq:lastPublished",
"value": "2024-01-11T21:45:00.668Z"
},
{
"name": "cq:lastModified",
"value": "2023-10-19T15:26:16.483Z"
}
]
}
},
...
What I want to do is to find a way to write the correct sort dotted expression to use the value of a calendarMetadata array element as sort field, for example:
query {
myFragmentList (sort: "_metadata.calendarMetadata[name='cq:lastModified'].value") {
...
}
}
but I cannot find a way to do that.
Any help is really appreciated.
Thank you.
Fabio
Solved! Go to Solution.
@costyfax : Have you explored this for sorting with GraphQL: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap...
Please try and let us know if it works.
thanks.
@costyfax : Have you explored this for sorting with GraphQL: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap...
Please try and let us know if it works.
thanks.
@Kamal_Kishor trying this I receive an InvalidSyntax error
@Kamal_Kishor yes I tried some options but I cannot find any syntax to access to a specified field inside _metadata.
The problem is that there is no a specific field under _metadata/calendarMetadata that extract a specific data (for ex. lastModified) but the calendar metadata is an array of key/value objects and I need (I think) a specific syntax to order by a value of an object inside this array.
The sort parameter for a graphql query is a string so the only option that I have is to use a dotted syntax to select a field but I cannot find any example that is using a field under _metadata.
Thank you again!
@costyfax Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
@kautuk_sahni we managed the order adding an editorial field into the content model. I couldn't find any solution to order by a specific metadata.
Views
Replies
Total Likes
I am also facing a similar issue where I want to sort via cq:lastPublished. I have done it via comparator method. But is there any efficient way to do it via querying? @costyfax @Kamal_Kishor
Views
Replies
Total Likes