Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

Order graphql results by calendar metadata value

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 9

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

View solution in original post

7 Replies

Avatar

Correct answer by
Level 9

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

Avatar

Level 9

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

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

 

Avatar

Level 2

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

Avatar

Administrator

@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

Avatar

Level 2

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

Avatar

Level 1

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