Order graphql results by calendar metadata value | Community
Skip to main content
Level 2
January 11, 2024
Solved

Order graphql results by calendar metadata value

  • January 11, 2024
  • 2 replies
  • 1807 views

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

Best answer by Kamal_Kishor

@costyfax : Have you explored this for sorting with GraphQL: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/content-fragments.html?lang=en#sorting
Please try and let us know if it works.
thanks.

2 replies

Kamal_Kishor
Community Advisor
Kamal_KishorCommunity AdvisorAccepted solution
Community Advisor
January 12, 2024

@costyfax : Have you explored this for sorting with GraphQL: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/content-fragments.html?lang=en#sorting
Please try and let us know if it works.
thanks.

Kamal_Kishor
Community Advisor
Community Advisor
January 12, 2024

@costyfax : Have you tried by replacing single quotes with a double quote-

sort: '_metadata.calendarMetadata[name="cq:lastModified"].value'

 

costyfaxAuthor
Level 2
January 12, 2024

@kamal_kishor trying this I receive an InvalidSyntax error

kautuk_sahni
Community Manager
Community Manager
January 23, 2024

@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.

Kautuk Sahni
costyfaxAuthor
Level 2
January 23, 2024

@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.

May 12, 2024

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