GraphQL Array | Community
Skip to main content
Level 2
September 30, 2021
Solved

GraphQL Array

  • September 30, 2021
  • 1 reply
  • 3327 views

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-fragments-graphql-samples.html?lang=en#sample-array-exact-value

 

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

    }
  }
}

   
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by KurtHo1

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

1 reply

KurtHo1AuthorAccepted solution
Level 2
November 10, 2021

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
Nikita_Mitroshin
Level 2
January 16, 2023

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.

Level 2
February 3, 2023

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"
      }
       ]}}
     )