Expand my Community achievements bar.

Multiple Tags as parameters for GraphQL persisted queries

Avatar

Level 2

Hello,

 

I would like to request data via GraphQL query based on a Tag multifield like this:

12nalk123_0-1733998333565.png

The parameters to return this data should be for example:

  • ["wknd-shared:season/summer"]
  • ["wknd-shared:season/summer", "wknd-shared:season/spring"]

I tried this query:

query ($adventureTags: [String]) {
  adventureList(
    filter: {
      adventureTags: {_logOp: OR, _expressions: [{values: $adventureTags, _operator: EQUALS}]}
    }) {
    items {
      _path
      adventureTags
    }
  }
}

It's only returning data if I add all parameters like this

  • ["wknd-shared:season/summer", "wknd-shared:season/spring"]

but does not return anything for this

  • ["wknd-shared:season/summer"]

Additionally I've tried to request the data with the persisted queries and the default cloud sdk dispatcher config like this:

http://localhost:8080/graphql/execute.json/wknd-shared/adventures-all%3BadventureTags%3D%5B%22wknd-s...

But that does not return any data. 

And if I run the query on author it works:

http://localhost:4502/graphql/execute.json/wknd-shared/articles-all;adventureTags=%3BadventureTags%3... 

 

It seems almost like this use case is not supported and I could not find any info about this in the Adobe docs. Can somebody help me here or has done something similar?

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

4 Replies

Avatar

Level 5

Hi @12nalk123 

 

I have tested out the same from my end, the reason why the first query is working and not the second one is it compares the full jcr property in the graphQL query and retrieve the result (below screenshot). It is expecting the same authored query params to be passed for the query to execute 

 

PRATHYUSHA_VP_0-1734617831182.png

 

 

For dispatcher URL, did you check if there's any error in the network console for any 404 issue ?

 

For reference :

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-6-5-17-graphql-persist...

 

Hope this helps

 

 

 

 

Avatar

Level 2

Hi @PRATHYUSHA_VP ,

thank you very much for helping. Regarding


@PRATHYUSHA_VP wrote:

I have tested out the same from my end, the reason why the first query is working and not the second one is it compares the full jcr property in the graphQL query and retrieve the result (below screenshot). It is expecting the same authored query params to be passed for the query to execute 


If I understand you correctly, this means that the

_logOp: OR

is not possible with tags/values inside an array?

 

------

 


For dispatcher URL, did you check if there's any error in the network console for any 404 issue ?


The issue is no 404 error but an empty result list:

{
  "data": {
    "adventureList": {
      "items": [
        
      ]
    }
  }
}

 AND I just noticed I had a wrong query string for the publisher URL. That means it's no publish/dispatcher problem but a general persisted query problem.

 

I use this parameter string

  • ;adventureTags=["wknd-shared:season/summer", "wknd-shared:season/spring"]

After encoding it looks like this

  • %3BadventureTags%3D%5B%22wknd-shared%3Aseason%2Fsummer%22%2C%20%22wknd-shared%3Aseason%2Fspring%22%5D

And if I use this on author/publisher/dispatcher an empty result is returned.

For example author: 

And in the GraphiQL UI there is a result returned (see image attached).

 

 

Avatar

Level 5

Hi @12nalk123 

 

As @sarav_prakash  mentioned, in order to fetch data which are tagged under single tag use CONTAINS in query, it should be something like below -

query {
  adventureList(
    filter: {
      adventureTags: {_logOp: OR, _expressions: [{value: "wknd-shared:activity/cycling", _operator: CONTAINS}]}
    }) {
    items {
      _path
      adventureTags
    }
  }
}

PRATHYUSHA_VP_1-1734712310780.png

 

If you want to fetch data which are tagged using multiple tags, follow as below :

 

PRATHYUSHA_VP_2-1734712354791.png

 

Also, regarding 404 issue , can you please check if content fragments are published and content is reflected

 

Hope this helps

 

Avatar

Level 6

Hi @12nalk123 , here is the example query you are looking for 

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql...

 

In your above query you are doing `_operator:EQUALS`. This will return result only if ALL values exactly match as you explain. Instead you must change to `_operator:CONTAINS`

 

So I wrote a query as 

query mywelcome {
  myContentList(
    filter: {_tags: {_expressions: [{value: "properties:orientation/portrait", _operator: CONTAINS}]}}
  ) {
    items {
      _tags
      _path
    }
  }
}

This returns all fragments tagged with portrait. Plus fragment with other tags are also returned. 

 

So your query should be changed as 

query ($adventureTags: [String]) {
  adventureList(
    filter: {
      adventureTags: {_logOp: OR, _expressions: [{values: $adventureTags, _operator: CONTAINS}]}
    }) {
    items {
      _path
      adventureTags
    }
  }
}