Expand my Community achievements bar.

SOLVED

Graphql Request for IDFilter gives coered Null Value Exception

Avatar

Level 2

I have a graphql query which takes IDFilter! as parameter and this works fine in the graphql editor and when i try to request from postman i am getting 

"Variable 'paths' has an invalid value: Variable 'paths' has coerced Null value for NonNull type 'IDFilter!'"
exception.
 
My Graphql Query

query ($expression:IDFilter!) {
internetList(
filter: {
_path: $expression
}
) {
items {
_path
}
}
}

Graphql Variables
{
   "expression":{
      "_logOp":"OR",
      "_expressions":[
         {
             "_operator": "EQUALS",
            "value":"/content/dam/sample/content-fragments/internet/internet1"
         },
         {
            "_operator": "EQUALS",
            "value":"/content/dam/sample/content-fragments/internet/internet2"
         }
      ]
   }
}


IndrajithPa_1-1727337666497.png

 


 




Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @IndrajithPa ,

 

Here are a few points you can check:


Variable Naming: Ensure the variable name in your GraphQL query (e.g., $expression) matches exactly with the name used in your Postman variables object.

JSON Structure: The request body in Postman should follow the correct format, including both "query" and "variables" keys, with properly structured JSON.

Headers: Make sure the Content-Type header is set to application/json.

Debugging Tip: If the query works in the AEM GraphQL editor but fails in Postman, it’s most likely due to incorrect payload formatting or mismatched variable names.

 

Regards,

Lavish Vasuja

View solution in original post

3 Replies

Avatar

Administrator

@narendragandhi@Rohan_Garg@abhishekanand_@Dipti_Chauhan@Mahedi_Sabuj@pulkitvashisth@pulkitvashisth@RahulMohan@anasustic@muskaanchandwani

Kindly take a moment to review this question and share your valuable insights. Your expertise would be greatly appreciated!



Kautuk Sahni

Avatar

Community Advisor

Hi @IndrajithPa ,

The error you’re facing:

Variable 'expression' has coerced Null value for NonNull type 'IDFilter!'

means that the shape of your expression variable doesn’t match what the IDFilter! type expects. This is very common when calling GraphQL from Postman or other HTTP clients outside the AEM GraphiQL UI.

Based on your query and error, here’s the corrected format you should use for your GraphQL Variables in Postman: GraphQL Query

query ($expression: IDFilter!) {
  internetList(filter: {
    _path: $expression
  }) {
    items {
      _path
    }
  }
}

Or, if you're trying to apply multiple OR filters, then that likely uses a LogicalExpression wrapper. But only if the schema supports it!

What You Must Check

Open your AEM GraphQL schema in the GraphiQL tool.

Check if the input for _path uses:

IDFilter! (single object), or

LogicalExpression! (for _logOp and _expressions).


If Schema Supports OR Filter with LogicalExpression

Then your query must change to:

Query:

query ($expression: LogicalExpression!) {
  internetList(filter: {
    _path: $expression
  }) {
    items {
      _path
    }
  }
}

Variables:

{
  "expression": {
    "_logOp": "OR",
    "_expressions": [
      {
        "_operator": "EQUALS",
        "value": "/content/dam/sample/content-fragments/internet/internet1"
      },
      {
        "_operator": "EQUALS",
        "value": "/content/dam/sample/content-fragments/internet/internet2"
      }
    ]
  }
}

Note: Use LogicalExpression! as the variable type if _logOp is being used. IDFilter! cannot accept a LogicalExpression structure — that’s why you're getting the coercion error.

Regards,
Amit

Avatar

Correct answer by
Level 2

Hi @IndrajithPa ,

 

Here are a few points you can check:


Variable Naming: Ensure the variable name in your GraphQL query (e.g., $expression) matches exactly with the name used in your Postman variables object.

JSON Structure: The request body in Postman should follow the correct format, including both "query" and "variables" keys, with properly structured JSON.

Headers: Make sure the Content-Type header is set to application/json.

Debugging Tip: If the query works in the AEM GraphQL editor but fails in Postman, it’s most likely due to incorrect payload formatting or mismatched variable names.

 

Regards,

Lavish Vasuja