Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

GraphQL Array

relaxabyte-corp
Level 2
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
relaxabyte-corp
Correct answer by
Level 2
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

1 Reply
relaxabyte-corp
Correct answer by
Level 2
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