question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
elorzafecommented, Feb 12, 2020

@chantlong I will transfer this issue to Amplify CLI repo, they will answer this better than me.

0reactions
github-actions[bot]commented, May 26, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found