Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,11 @@ void main({
where: Blog.NAME.eq(blogName) & Blog.ID.eq(blog.id),
limit: _limit,
);
final res = await Amplify.API.query(request: req).response;
final data = res.data;
final blogs = [blog];
// Walk all pages: the match may be on a later scan page in a large table.
final items = await listAllPages<Blog>(req);

expect(res, hasNoGraphQLErrors);
expect(data?.items.length, 1);
expect(data?.items, containsAll(blogs));
expect(items.length, 1);
expect(items, containsAll([blog]));
});

testWidgets(
Expand Down
18 changes: 18 additions & 0 deletions packages/api/amplify_api/example/integration_test/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@ Future<Sample> deleteSample(Sample sample) async {
return sample;
}

/// Collects every item from a paginated `list` [request] by following `requestForNextResult` (a single scan page can miss matches in a large table).
Future<List<T?>> listAllPages<T extends Model>(
GraphQLRequest<PaginatedResult<T>> request,
) async {
final items = <T?>[];
GraphQLRequest<PaginatedResult<T>>? nextReq = request;
while (nextReq != null) {
final res = await Amplify.API.query(request: nextReq).response;
expect(res, hasNoGraphQLErrors);
final data = res.data;
items.addAll(data?.items ?? const []);
nextReq = (data?.hasNextResult ?? false)
? data!.requestForNextResult
: null;
}
return items;
}

Future<void> deleteTestModels() async {
await Future.wait(blogCache.map(deleteBlog));
await Future.wait(postCache.map(deletePost));
Expand Down
Loading