Expand my Community achievements bar.

AEM CLoud GraphQL Filter using string array

Avatar

Level 3

Hi Team,

 

Could you please help me on GraphQL persistent queries.

The use case is I want to pass some group names in query paramaters and I want to filter the CF's matching with any group name.

I am using query like this 

query ($userGroups: [String]!) {
  sNewFragmentList(filter: {
    deliveryGroup: {
      _expressions: [
        {
          values: $userGroups
          _operator: CONTAINS
        }
      ]
    }
  }) {
    items {
      _path
      title
      description
      deliveryGroup 
    }
  }
}

And I am passing parameters as 

{
  "userGroups": "group1,group2,group3"
}

 

This query is not working at all, could anyone pls help me to check every group from the parameters list and filter only those fragments.

 

Thanks.

8 Replies

Avatar

Level 7

Hi @SDusane 

 

Firstly, the type of param you're trying to filter should be of type string array [String]. Refer to example like below : 

 

PRATHYUSHA_VP_0-1739857527090.png

 

If it's not string array parameter, try something like below : 

 

PRATHYUSHA_VP_1-1739857741198.png

 

You can update, operator parameter (_operator) as per your requirement

 

Here's the similar example in experience league docs --

 

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql...

 

Hope this helps

 

Thanks

 

Avatar

Level 3

Hi @PRATHYUSHA_VP 

 

Thanks for the help!

I am trying below query 

query ($userGroups: [String]) {
  sNewFragmentList(
    filter: {
      deliveryGroup: {
        _logOp: OR,
        _expressions: [{
          values: $userGroups,
          _operator: CONTAINS
        }]
      }
    }
  ) {
    items {
      title
      description
      deliveryGroup
    }
  }
}

With the query parameter 

{
  "userGroups": ["group1","group2"]
}

It is still not working. If I give only 1 parameter the query is working but not with array values.

Can you pls suggest me some fix.

 

Thanks.

Avatar

Level 7

@SDusane 

 

Can you send the type of parameter for deliveryGroup in CF field ?

 

Thanks

Avatar

Level 3

Hi @PRATHYUSHA_VP 

 

It is like 

"deliveryGroup": [
            "group1",
            "group2"
          ]

 

Thanks.

Avatar

Level 7

Hi @SDusane 

 

String[] looks for exact same match, so try something like below -

 

PRATHYUSHA_VP_0-1739872513134.png

 

Below is the thread which explains similar query -

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/graphql-array/td-p/425661

 

Hope this helps 

 

Avatar

Level 7

Hi @SDusane ,

Change _operator: CONTAINS to _operator: IN for matching arrays.
Query: Checks if any value in the userGroups array matches values in the deliveryGroup array.

query ($userGroups: [String]) {
  sNewFragmentList(
    filter: {
      deliveryGroup: {
        _logOp: OR,
        _expressions: [{
          values: $userGroups,
          _operator: IN
        }]
      }
    }
  ) {
    items {
      title
      description
      deliveryGroup
    }
  }
}
{
  "userGroups": ["group1", "group2"]
}

Avatar

Level 3

Thanks @AmitVishwakarma 

I could see this error

 

SDusane_0-1739933760692.png

 

 

IN is not the value we can use.

 

Thanks.

Avatar

Level 5

Hi @SDusane , could you please try below filter? Ensure you have name as VALUE instead of VALUEs

 

filter: {deliveryGroup: {_expressions: [{value: $userGroups, _operator: CONTAINS}]}}

 

Thanks,

Ramesh.