AEM GraphQL API: Atleast one filter not working as expected | Community
Skip to main content
New Participant
September 29, 2022
Solved

AEM GraphQL API: Atleast one filter not working as expected

  • September 29, 2022
  • 1 reply
  • 527 views

I want to implement atleast one filter provided by AEM on an array field to filter the categories which contains atleast one of the values:

 

_expressions: [ { _apply: AT_LEAST_ONCE, values: [ "health", "fitness" ] } ]

 

Now when I run the query, I get the following error:

 

{ "errors": [ { "message": "Exception while fetching data (/output) : Cannot compare single value to an array.", "locations": [ { "line": 2, "column": 3 } ], "path": [ "output" ], "extensions": { "classification": "DataFetchingException" } } ], "data": null }

 

Can someone help me debugging why this error shows up and how can I avoid it?

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 Saravanan_Dharmaraj

Can you try the similar to below example given in https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/sample-queries.html?lang=en#sample-all-persons-jobs-smith 

Sample Query - All Persons that have a name of “Jobs” or “Smith”

This will filter all persons for any that have the name Jobsor Smith.

 

Sample Query

query {
  personList(filter: {
    name: {
      _logOp: OR
      _expressions: [
        {
          value: "Jobs"
        },
        {
          value: "Smith"
        }
      ]
    }
  }) {
    items {
      name
      firstName
    }
  }
}
 

Sample Results

{
  "data": {
    "personList": {
      "items": [
        {
          "name": "Smith",
          "firstName": "Adam"
        },
        {
          "name": "Smith",
          "firstName": "Joe"
        },
        {
          "name": "Jobs",
          "firstName": "Steve"
        }
      ]
    }
  }
}

1 reply

Saravanan_Dharmaraj
Saravanan_DharmarajAccepted solution
New Participant
September 29, 2022

Can you try the similar to below example given in https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-api/sample-queries.html?lang=en#sample-all-persons-jobs-smith 

Sample Query - All Persons that have a name of “Jobs” or “Smith”

This will filter all persons for any that have the name Jobsor Smith.

 

Sample Query

query {
  personList(filter: {
    name: {
      _logOp: OR
      _expressions: [
        {
          value: "Jobs"
        },
        {
          value: "Smith"
        }
      ]
    }
  }) {
    items {
      name
      firstName
    }
  }
}
 

Sample Results

{
  "data": {
    "personList": {
      "items": [
        {
          "name": "Smith",
          "firstName": "Adam"
        },
        {
          "name": "Smith",
          "firstName": "Joe"
        },
        {
          "name": "Jobs",
          "firstName": "Steve"
        }
      ]
    }
  }
}