'AWS AppSync GraphQL query failing with Status Code 400

I've been trying to fix this 400 issue but no luck so far. When running a total count query with pagination, it works just fine but as soon as I expand my query to add edges, cursor and node, it breaks.

My hunch says, there is some discrepancy between resolver and Schema, could be wrong. Please do not suggest to modify the Schema, my only option is to update the resolver to make it work. Please help!

The query with count and pagination (Works just fine)-

query MyQuery {
  orders(orderId: "3y8") {
    totalCount
    pageInfo {
      hasNextPage
      endCursor
      hasPreviousPage
      startCursor
    }
  }
}

Response -
{
  "data": {
    "orders": {
      "totalCount": 7,
      "pageInfo": {
        "hasNextPage": true,
        "endCursor": "eyJ==",
        "hasPreviousPage": false,
        "startCursor": null
      }
    }
  }
}

I have added Schema, query and resolver which is VTL based. Also CloudWatch logs, which clearly shows the response i am getting - Edges : [{Node, Cursor}]

type Query {
        orders(
        orderId: String,
        last: Int,
        before: String,
        first: Int,
        after: String
    ): Connection
}

type Connection {
    edges: [Edge!]!
    pageInfo: PageInfo!
    totalCount: Int!
}

interface Edge {
    node: Node!
    cursor: String!
}

interface Node {
    id: String!
}

  orders(orderId: "3y8", first: 1) {
    totalCount
    edges {
      cursor
    }
  }
}

Resolver->

#set($edges = [])
#set( $nextTokenCursor = "" )
#if($context.result.nextToken) 
    #set($nextTokenCursor = $context.result.nextToken)
#end

#foreach($item in $context.result.items)
    $util.quiet($edges.add({"node": $item, "cursor": $nextTokenCursor}))
#end
{
          "edges": $util.toJson($edges),
          "totalCount": $util.toJson($ctx.result.items.size()),
          "pageInfo": {
            "hasPreviousPage": false,
            "hasNextPage": #if($context.result.nextToken) true #else false #end,
            "endCursor": $util.toJson($nextTokenCursor)
          }
}

CloudWatch Logs ->

"transformedTemplate": "{edges=[{node={summary={Records}, customer={}}, cursor=eyJ==}], totalCount=1, pageInfo={hasPreviousPage=false, hasNextPage=true, endCursor=eyJ== }}"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source