How to query by a type column + userId + createdAt
See original GitHub issue** Which Category is your question related to? **
AWS Amplify + GraphQL Queries
** What AWS Services are you utilizing? ** Cognito + AWS AppSync, ** Provide additional details e.g. code snippets **
type MyTable
@model
@auth(
rules: [
{ allow: owner, ownerField: "userId", operations: [create, update, read] }
]
)
@key(
fields: [“type”, "createdAt"]
name: "SortByType"
queryField: "listByType"
) {
id: ID!
userId: String!
type: String!
createdAt: AWSTimestamp!
}
The column type can be “A” or “B”.
I query by
await API.graphql(
graphqlOperation(listByInterval, {
type: 'A',
sortDirection: ModelSortDirection.DESC,
})
The query will automatically query by the logged in userId. Amplify has a default limit of 10.
If my data is on the 20th row, The first search will return me 0 results. If I set the limit to 30, I get my results back.
So I tried changing the schema to 3 key fields and kept my Database to less than 10 items.
await API.graphql(
graphqlOperation(listByInterval, {
userId: userId
typeCreatedAt: {
eq: {
type: 'A',
},
},
sortDirection: ModelSortDirection.DESC,
})
My createdAt timestamps are based on AWSTimestamp I still get 0 results even though I have items in the DB that match it.
I am not sure what I am doing wrong, so any advice would be appreciated.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
How to Get Newest Data with `created_at` Column
try this query. SELECT * FROM test1 n WHERE created_at=(SELECT MAX(created_at)FROM test1 WHERE staflow=n.staflow) order by id.
Read more >Finding the Oldest/Youngest Records Within a Group
A common query that crops up in web apps is finding the oldest or the most recent record in a single table. This...
Read more >Use an updated_at Column in Your MySQL Table (and make ...
Use an updated_at Column in Your MySQL Table (and make it update automatically) ; INSERT ; INTO orders (user_id, amount, created_at) ; VALUES...
Read more >unknown column 'id' in 'field list' sequelize - You.com
SELECT `noteId`, `noteType`, `referenceType`, `referenceId`, `note`, `userId`, `userName`, `createdAt`, `updatedAt`, `id` FROM `note` AS `Note` WHERE `Note`.` ...
Read more >Data model (Reference) - Prisma
The following query uses the Prisma Client generated from this data model to ... Scalar types (includes enums) that map to columns (relational...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@chantlong I will transfer this issue to Amplify CLI repo, they will answer this better than me.
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.