Expand my Community achievements bar.

SOLVED

GraphQL Array

Avatar

Level 2

In the AEM Sample Queries for filtering tags, the sample CF defines the Categories field as a Tag data type. It uses a filter to find CFs by two tags.

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/assets/admin/content-fragme...

 

I am trying to emulate this filter on a Tag field. I created a model with a Tag field named tagfield. When I run my query below, I get this error:

...

"message": "Exception while fetching data (/digitalProductList) : Cannot compare single value to an array."

...

"extensions": {
    "classification": "DataFetchingException"
}

 

I checked the docs and tagfield has a "values: [String]" option in the filter.

 

If I change it to value: "show:comedy", then I get all CFs with that tag. Any ideas why the datatype tag field in my query would be a single string while the example works as a String Array? How can I change my model or query to filter on multiple tags?

 



Sample QueryMy Query
query {
  cityList(filter: {
    categories: {
      _expressions: [ {
        values: [
          "city:beach",
          "city:na"
        ]
      } ]
    }
  }) {
    items {
      name
      population
      country
      categories
    }
  }
}

query {
  myExampleList (filter: {
    tagfield: {
      _expressions: [ {
        values: [
          "show:comedy",
          "show:drama"
        ]
      } ]
    }
  }) {
    items {
      _path
      tagfield
      name

    }
  }
}

   
1 Accepted Solution

Avatar

Correct answer by
Level 2

I couldn't figure out why a field that is a multifield array and an expression that accept arrays kept generating the error. I never replicated the tutorial.

 

I ended up achieving what I wanted by changing the query to this:

 

query {
  myExampleList (filter: {
    tagfield: {
      _logOp: AND
      _expressions: [ 
        {value: "show:comedy"},
        {value: "show:drama"}
        ]
      } 
  }) {
    items {
      _path
      tagfield
      name
    }
  }
}

Bonus:
If you want to pass the tags in as a variable, you'd pass the _logop and _expression as json in a variable
($tagfield: StringArrayFilter!) and then set tagfield: $tagfield

View solution in original post

3 Replies

Avatar

Correct answer by
Level 2

I couldn't figure out why a field that is a multifield array and an expression that accept arrays kept generating the error. I never replicated the tutorial.

 

I ended up achieving what I wanted by changing the query to this:

 

query {
  myExampleList (filter: {
    tagfield: {
      _logOp: AND
      _expressions: [ 
        {value: "show:comedy"},
        {value: "show:drama"}
        ]
      } 
  }) {
    items {
      _path
      tagfield
      name
    }
  }
}

Bonus:
If you want to pass the tags in as a variable, you'd pass the _logop and _expression as json in a variable
($tagfield: StringArrayFilter!) and then set tagfield: $tagfield

Avatar

Level 2

Just additional info that the same issue reproduces for me on AEM 6.5.12, while on 6.5.15 it works fine.

Anyways, the way to go is to use the provided solution.

Avatar

Level 2

Although 6.5.15 didnt give the error I encountered with 6.5.12, the results are different

I created a simple model with a title an skulist where skulist is a multifield value in the content fragment

With 6.5.15, the following query wouldnt return any results

{
  mymodelList
  (filter: {skuids:{
     _expressions: [     
        {     
          values:  ["SKU0"]          
        }
       ]}} )
    {
    items{
      title
      skuids
    }
}

but when the values list in the query is updated with all the values in the multi field then it returns values

 

ex: when values:  ["SKU0"]    is replaced withvalues:  ["SKU0","SKU11","SKU12"]    then the result is{
  "data": {
    "mymodelList": {
      "items": [
        {
          "title": "Easter list",
          "skuids": [
            "SKU0",
            "SKU11",
            "SKU12"
          ]
        }
      ]
    }
  }
}

tired to use _logOp:OR before _expressions that also didnt return any results

So, the following filter had only 2 of the 3 multifiled values in the content fragment and didnt return any results

(filter: {skuids:{
    _logOp:OR
     _expressions: [     
        {     
          values: [ "SKU0","SKU11"]          
        }
       ]}}
     )

 

However, when updated to the below filter, it returned results as expected

(filter: {skuids:{
    _logOp:OR
     _expressions: [     
        {     
          value:  "SKU0"          
        },
      {
        value: "SKU11"
      }
       ]}}
     )