Expand my Community achievements bar.

SOLVED

AEM GraphQL API: Atleast one filter not working as expected

Avatar

Level 5

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?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Can you try the similar to below example given in https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap... 

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

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Can you try the similar to below example given in https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/headless/graphql-ap... 

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