GraphQL query with filter returns no results on GSI but DynamoDB query with filter shows data
Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the Amplify Console GitHub Issue Tracker
Describe the bug A clear and concise description of what the bug is. I have a model entry with primary key consisting of 2 fields, primary key is type, sort key is code. Defined @key directive for this with a query field. When I do graphql query specifying the type value and a filter on a field in the model, graphql returns no results BUT if I run the same query against the DynamoDB table in DynamoDB console, the query returns the data
Amplify CLI Version
You can use amplify -v to check the amplify cli version on your system
4.29.3
To Reproduce Steps to reproduce the behavior or terminal output if applicable create a model with fields: type code fieldA
add @key with 2 fields (type & code) queryfield: "getByCodeSorted" do graphql query against model with type value specified & a filter value for fieldA
Expected behavior A clear and concise description of what you expected to happen. Expect the query to return data
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. Mac/Windows/Ubuntu]
- Node Version. You can use
node -vto check the node version on your system OS: Win 10 64 node 14.6
Additional context Add any other context about the problem here.
Any update on this breaking issue? This is causing a number of my queries to return null items when data does exist
Update to 4.29.6 and now queries that used to work are also failing to return data...... :(
@nikhname any feedback on this please? This is becoming a major impact on our system and preventing a production release
The most likely explanation is that the items you are trying to find are not in the initial result set from DynamoDB and you would need to page through the data.
In DynamoDB filters are run after limit (this might be the opposite order you are accustomed to seeing). If you have a limit of 10 and a filter, DynamoDB will fetch 10 items maximum and then filter from there.The console is doing automatic pagination for you when you are using filters.
Additionally, filters have a much more limited use-case in DynamoDB than a WHERE clause in SQL. Filters should mainly be used to reduce the amount of bytes put on the network. In almost all other cases you will want to just use sort key values.
@frankclaassen Is there a version where you did see results? If so I could try to reproduce in between versions. I tried to reproduce this latest given the following schema and I did was able to get results.
type Sample
@model
@key(name: "ByTypeCode", fields: ["type", "code"], queryField: "getByCodeSorted")
{
id: ID
type: String
code: String
fieldA: String
}
@SwaySway updated to the latest version and it seems to be working, can close this issue thanks
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.