Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

AEMaaCS GraphQL: Sorting, tags and page reference

Avatar

Level 2

Hello!

We are struggling with a GraphQL query on our AEMaaCS publish instance.

For showing certain news on our Android and iOS mobile apps, we'd like to query a list of article content fragments...

  • of a specific path
  • after specific date
  • sorted by date
  • having a particular cq:tags tag set
  • returning the _publishURL of the page that references the content fragment

Current state:

  • Date works.
  • Path works.
  • Sorting by date will be supported with the March 2023 release.
  • Checking for tags did work in AEM 6.5 but now it seems it does not work anymore? Do we miss something?
  • The _references attribute only returns "RTE inline references" and not the page(s) that reference the content fragment. Is there a way to accomplish that?

Our current query:

query {
  articleList(
    # does not work
    # sort: "articleDate DESC",
    filter: {
      _path: {
        _expressions: [
        {
          # Path e.g. /content/dam/gpa/articles
          value: "/content/dam/oegb/articles"
         _operator: STARTS_WITH
        }]
      },
      articleDate: {
        _expressions: [
        {
          # Datetime of last time queried by client
          value: "2023-02-15T00:00:00.000Z"
         _operator: AFTER
        }]
      },
      # does not work
      # _tags: {_expressions: [{value: "meinbrapp", _operator: CONTAINS}]}
    }) {
    items {
      _path
      topic
      title
      subtitle
	    articleDate
      previewText {
        html
      }
      mainText {
        html
      }
      _metadata {
        stringArrayMetadata {
          name,
          value
        }
      }
    },
    _references {
      ... on PageRef {
        _publishUrl
      }
    }
  }
}

 

Any hint is appreciated.

 

Thank you!

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 5

@martinkastler , you dont need array to check for single value. I test from my local a similar query and this works:

 

query mySearch($pageSize: Int, $startIndex: Int, $input: String) {
  releaseNotesMasterList(
    filter: {
      input: {_expressions: {_operator: EQUALS, value: $input}}, 
      _path: {_expressions: {_operator: STARTS_WITH, value: "/content/dam/content-fragments/demo"}},
      _tags:{_expressions:{_operator:CONTAINS, value:"test1"}}
    }
    limit: $pageSize
    offset: $startIndex
    sort: "releaseDate DESC"
  ) {
    items {
      _path
    }
  }
}

 

When I comment _tags, query returned 2 frags and with _tags filter returned only 1. 

 

So in your case can you try 

# _tags: {_expressions: [{value: "meinbrapp", _operator: CONTAINS}]}

to 

# _tags: {_expressions: {value: "meinbrapp", _operator: CONTAINS}}

and see if it helps? But honestly with squarebrackets also worked for me.

 

1 more consideration, tag references work ONLY with cq:tags. When you goto Tagging and check references from the tag, your CF must show up under References like this 

sarav_prakash_0-1725489918065.png

Tag references will NOT work for custom tag properties. 

 

Last consideration, incase you are trying against custom properties, I ran into weird issue and adding `_ignoreCase: true` solved for me. I documented here. https://medium.com/@bsaravanaprakash/how-to-filter-properties-with-custom-namespaces-in-aem-graphql-...

 

Hope this helps. 

View solution in original post

2 Replies

Avatar

Administrator

@AsifChowdhury @Shiv_Prakash_Patel @nitesh_kumar @Rohit_Utreja 

Can you please dedicate some time to review this AEM question and offer your expert insights? Additionally, if you could provide the author with some guidance or direction to tackle the problem, it would be most appreciated.



Kautuk Sahni

Avatar

Correct answer by
Level 5

@martinkastler , you dont need array to check for single value. I test from my local a similar query and this works:

 

query mySearch($pageSize: Int, $startIndex: Int, $input: String) {
  releaseNotesMasterList(
    filter: {
      input: {_expressions: {_operator: EQUALS, value: $input}}, 
      _path: {_expressions: {_operator: STARTS_WITH, value: "/content/dam/content-fragments/demo"}},
      _tags:{_expressions:{_operator:CONTAINS, value:"test1"}}
    }
    limit: $pageSize
    offset: $startIndex
    sort: "releaseDate DESC"
  ) {
    items {
      _path
    }
  }
}

 

When I comment _tags, query returned 2 frags and with _tags filter returned only 1. 

 

So in your case can you try 

# _tags: {_expressions: [{value: "meinbrapp", _operator: CONTAINS}]}

to 

# _tags: {_expressions: {value: "meinbrapp", _operator: CONTAINS}}

and see if it helps? But honestly with squarebrackets also worked for me.

 

1 more consideration, tag references work ONLY with cq:tags. When you goto Tagging and check references from the tag, your CF must show up under References like this 

sarav_prakash_0-1725489918065.png

Tag references will NOT work for custom tag properties. 

 

Last consideration, incase you are trying against custom properties, I ran into weird issue and adding `_ignoreCase: true` solved for me. I documented here. https://medium.com/@bsaravanaprakash/how-to-filter-properties-with-custom-namespaces-in-aem-graphql-...

 

Hope this helps.