graphqldatadog

Unable to pass valid graphQL request body inside data dog API test


I am building multi-step api test in data dog by passing graphQL request to fetch data from source. I am passing below graphQL request body w/ variables but it seems this data dog is unable to parse this request. PAGESIZE is local variable that holds data type of int

query Organizations($pageSize: Int) {
   organizations(pageSize: $pageSize) {
    count
    items {
      id
    }
  }
}

{
  "pageSize" {{ PAGESIZE }}
}

As you can see in the attached screenshot, the variable section is considered to be invalid and shows red validation error. So far I have tried following formats in variable section but all shows validation errors

"pageSize": {{PAGESIZE}} "pageSize": 10 pageSize: {{PAGESIZE}} pageSize:10

What is working? When I remove the variable section from the graphQL request, the request successfully returns all results but I want to return 10 records not all of them.

Does anyone knows what is the reason behind this error and how do I fix it?enter image description here


Solution

  • This is what solved the problem for me. Changing the Body Type in request body to application/json and converting the body to JSON type. I can use local and global variables as well in the request body

    {
      "query": "query Organizations($pageSize: Int) { organizations(pageSize: $pageSize) { count items { id } }}",
      "variables": {
        "pageSize": {{ PAGESIZE }}
      }
    }
    
    You have to convert graphQL query to a JSON body. I used this converter graphQL to JSON and it worked:
    
    https://datafetcher.com/graphql-json-body-converter