0

I am trying to perform a listItem call with AppSync from my NextJS front-end. I can successfully make the following calls:

  • listItems from front-end
  • listItems with filter from the AppSync console.

When I try the call I get this error:

Error: Invalid AST Node: { query: "\n  query ListCards(\n    $filter: ModelCardFilterInput\n    $limit: Int\n    $nextToken: String\n  ) {\n    listCards(filter: $filter, limit: $limit, nextToken: $nextToken) {\n      items {\n        approvedTime\n        approvedUser\n        canRead\n        canUpdate\n        clientID\n        id\n        input\n        feedback\n        name\n        output\n        scheduledTime\n        status\n        type\n        createdAt\n        updatedAt\n        _version\n        _deleted\n        _lastChangedAt\n      }\n      nextToken\n      startedAt\n    }\n  }\n", filter: { cardID: [Object] } }.

My failing code:

  const listCardsFilteredResponse = (await API.graphql(
    graphqlOperation({
      query: listCards,
      filter: { clientID: { eq: "d9a6c7a2-45b1-48a8-b012-5908d216f86f" } },
    })
  ))

My working js code:

  const listCardsResponse = (await API.graphql(
    graphqlOperation(listCards)
  ))

My working query in the AppSync console:

query MyQuery {
  listCards(filter: {clientID: {eq: "d9a6c7a2-45b1-48a8-b012-5908d216f86f"}}) {
    nextToken
    startedAt
    items {
      id
      name
    }
  }
}

I've looked for similar posts, but I still haven't had any luck.

JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71

1 Answers1

0

I fixed the problem by rewriting the code from:

    graphqlOperation({
      query: listCards,
      filter: { clientID: { eq: "d9a6c7a2-45b1-48a8-b012-5908d216f86f" } },
    })

to:

    graphqlOperation(listCards, {
      filter: { clientID: { eq: "d9a6c7a2-45b1-48a8-b012-5908d216f86f" } },
    })

Confusingly, this is in contradiction to the example in the documentation - https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/js/#compound-filters :

await API.graphql({ query: listProducts, variables: { filter: filter}}));
JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71