multimeric / AmplifyCountDirective

Count the number of items in your DynamoDB tables using Amplify
12 stars 1 forks source link

Unable to filter the count using attributeExists on its own #8

Closed Tedsterh closed 2 years ago

Tedsterh commented 2 years ago

Hi,

I am trying to filter based on wether an attribute exists or not, if I use an and statement alongside the attributeExists I am able to get a count but on its own it throws and error

"errors": [
    {
      "path": [
        "fuseable"
      ],
      "data": null,
      "errorType": "Lambda:Unhandled",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "ExpressionAttributeValues must not be empty"
    }
  ]
multimeric commented 2 years ago

Can you show me the schema and the query that you used? You can adjust type names if you want to keep any of it private, but I think I need to know the structure.

Tedsterh commented 2 years ago
type Trait @model @searchable @count {
    id: ID!
    trait: String! @default(value: "trait")
    name: String! @index(name: "traitByName", queryField: "traitByName", sortKeyFields: ["animalId"])
    animalId: ID @index(name: "traitByAnimal", queryField: "traitByAnimal", sortKeyFields: ["createdAt"])
    animal: Animal @belongsTo(fields: ["animalId"])
    createdAt: AWSDateTime!
}

so I am trying to filtering the count based on how many traits have an animal id, luckily I already have a default string on every trait so that I could use sorting on amplify indexes, but I have to have this extra filter {trait: {eq: "trait"}} alongside the {animalId: {attributeExists: true}}

Hope this helps

multimeric commented 2 years ago

So you are saying your overall filter is this?

{
  countTrait(filter: {
    and: {
      trait: {eq: "trait"},
      animalId: {attributeExists: true}}
  })
}

Can you run this query directly in the AppSync console and let me know if it gives you the same response?

Tedsterh commented 2 years ago

Yes that's the query sorry, I can run that one fine but as soon as I remove the trait filter and leave just the attributeExists I get the error

multimeric commented 2 years ago

Fixed in 1.1.0.