I am looking for a way to sort GraphQL results by custom metadata field. There is a way how to filter by custom metadata field that is described in documentation, however, I cannot find how to sort. Is it possible?
The GraphQL result sorting currently supported the following fields only, It's possible to extend GraphQL extension in sites 9.1.
- CREATION_DATE
- INITIAL_PUBLISH_DATE
- ITEM_ID ITEM_TYPE
- LAST_PUBLISH_DATE
- NAMESPACE_ID
- OWNING_PUBLICATION_ID
- PUBLICATION_ID
- TITLE
- UPDATED_DATE
Example:
{
items(
filter: {
customMeta: {scope: Item, key: "mykey", value: "42"},
sort:{sortBy:LAST_PUBLISH_DATE, order:Descending}
}
) {
edges {
node {
id
publicationId
namespaceId
itemId
itemType
title
customMetas {
edges {
node {
key
value
}
}
}
}
}
}
}
Indeed!. Refer to the SDL Documentation for GraphQL query result sorting more details.
I hope it helps.
-
Is there any sample code on how to extend GraphQL extension in sites 9.1? – Stan Kroshchenko Sep 18 '19 at 17:12
-
Good question, @Stan. It's probably worth starting a new TRex question so others can find it along with the eventual answer. :-) – Alvin Reyes♦ Sep 19 '19 at 0:52