Pagination with Filtering in DynamoDB Template
See original GitHub issueSchema:
type Query {
getUserTwitterFeed(handle: String!): User
}
type Tweet {
tweet_id: String!
tweet: String!
retweeted: Boolean!
retweet_count: Int
favorited: Boolean!
}
type TweetConnection {
items: [Tweet]
nextToken: String
}
type User {
name: String!
handle: String!
location: String!
description: String!
followers_count: Int!
friends_count: Int!
favourites_count: Int!
followers: [String]
tweets(limit: Int, nextToken: String): TweetConnection
}
schema {
query: Query
}
Request Mapping Template:
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression": "handle = :handle",
"expressionValues": {
":handle": {
"S": "$context.source.handle"
}
}
},
"limit": #if($context.arguments.limit) $context.arguments.limit #else 10 #end,
"nextToken": #if($context.arguments.nextToken) "$context.arguments.nextToken" #else null #end
#if(${context.arguments.keyword})
,"filter": {
"expression": "contains (#tweet, :keyword)",
"expressionNames" : {
"#tweet" : "tweet"
},
"expressionValues": {
":keyword": { "S": "${context.arguments.keyword}" }
}
}
#end
}
Response Mapping Template:
{
"items": $util.toJson($context.result.items),
"nextToken": $util.toJson($context.result.nextToken)
}
Query:
I am trying to write a mapping template to paginate tweets with a given filter. My dynamodb table has simple structure: hash key = handle, sort key = tweet_id
When I don’t pass keyword parameter, everything runs fine. But now I added another condition to the mapping template i.e if the keyword is an input then filter tweets by keyword. But I see weird error in the above screenshot. Took reference to add Query Filters from here
Any idea what is happening? Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top Results From Across the Web
Pagination with Filtering using Query Operation in DynamoDB ...
Lets check your example - You have boolean and you have index over that field. Lets say 50% of items are false and...
Read more >DynamoDB Pagination - The Ultimate Guide (with Example)
Pagination, in general, is a technique to split the data records retrieved from DynamoDB into multiple segments. As a database that supports ...
Read more >Pagination with Filtering in DynamoDB Template #3209 - GitHub
I would like to be able to filter a pagination result before the limit is taken into consideration. I have already tried Global...
Read more >Paginating table query results - Amazon DynamoDB
DynamoDB paginates the results from Query operations. With pagination, the Query results are divided into "pages" of data that are 1 MB in...
Read more >The surprising properties of DynamoDB pagination
The filter expression is run after DynamoDB fetches the results, so it is almost the same as doing it on the client-side, the...
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 FreeTop 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
Top GitHub Comments
I find this whole dynamodb / appsync / filtering stuff unworkable. If you filter you can’t trust the nextToken for pagination, because you don’t know if the next page has results that might be filtered. The only way around it would be to have something in your sortkey that you can sort on so you group the records you want to keep after the filter and you can do some kind of predictive pagination.
We are really hitting limits with Appsync and Dynamo. Imagine having pagination in the middle of a 5 function pipeline resolver. You would have to run the whole pipeline 5 times 😃
I am also interested in a solution for this. I would like to be able to filter a pagination result before the limit is taken into consideration