6

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?

1 Answer 1

7

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 for more details.

Update: This is now fixed and available HF and also needs a fix for the DXA Graphql provider level(DXA 2.2.3 is available at maven/nuget). please reach out to SDL support.

Example query:

{
    items(
    filter:{
      itemTypes:COMPONENT
      publicationIds: 5
      schema: {
        id:122
      }
    }
    sort:{
      order: Descending
      keyType: DATE
      key: "dateCreated"
      sortBy: CUSTOM_META
    }
  ){
    edges{
      node{
        customMetas {
          edges {
            node {
              key
              value
            }
          }
        }
      }
    }
  }
}

I hope it helps.

2
  • Is there any sample code on how to extend GraphQL extension in sites 9.1? Sep 18, 2019 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. :-) Sep 19, 2019 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.