I’m working on a project using AWS Amplify and AppSync with the following simplified schema:
type Sample @model @auth(rules: [{ allow: private, provider: userPools, operations: [read, update] }]) {
type_id: String! @primaryKey(sortKeyFields: ["type"])
type: String!
place: Place
}
type Place {
placeId: ID
placeName: String
posts: [Post]
}
type Post {
postId: ID!
content: String
}
I want to implement pagination for the posts field when querying a Sample object. However, I’m using a ‘get’ query instead of a ‘list’ query, and posts is defined as an array rather than a connection. Here’s an example of the query I’m trying to use:
query GetLocalWithPaginatedPosts($type_id: String!, $type: String!, $postsLimit: Int, $postsNextToken: String) {
getLocal(type_id: $type_id, type: $type) {
type_id
type
place {
placeId
placeName
posts(limit: $postsLimit, nextToken: $postsNextToken) {
postId
content
}
}
}
}
The problem is that pagination (limit and nextToken) for the posts field doesn’t work. All posts are returned regardless of the limit specified.
How can I implement pagination for the nested posts array in this ‘get’ query scenario?
Do I need to modify my schema to use a connection type for posts, or is there a way to paginate the array directly?
If I need to use a connection type, what changes should I make to my schema?
What kind of custom resolver (VTL or JavaScript) would I need to implement this pagination?
I’m using Amplify CLI version 12.12.3 and have tried both local mocking and deploying to AWS, but the pagination isn’t working in either case.
Any help or guidance would be greatly appreciated!