From 1356a2e4389e0bfb68ba17a670b2847af1a90e6c Mon Sep 17 00:00:00 2001 From: Varshitha Pamisetty Date: Tue, 18 Aug 2026 22:14:41 +0200 Subject: [PATCH] test(api): Paginate list-predicate query so matches aren't missed on later scan pages --- .../integration_test/graphql/iam_test.dart | 10 ++++------ .../example/integration_test/util.dart | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/api/amplify_api/example/integration_test/graphql/iam_test.dart b/packages/api/amplify_api/example/integration_test/graphql/iam_test.dart index 28ceaa71e4e..80f6e2aa2a2 100644 --- a/packages/api/amplify_api/example/integration_test/graphql/iam_test.dart +++ b/packages/api/amplify_api/example/integration_test/graphql/iam_test.dart @@ -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(req); - expect(res, hasNoGraphQLErrors); - expect(data?.items.length, 1); - expect(data?.items, containsAll(blogs)); + expect(items.length, 1); + expect(items, containsAll([blog])); }); testWidgets( diff --git a/packages/api/amplify_api/example/integration_test/util.dart b/packages/api/amplify_api/example/integration_test/util.dart index 8941c967da3..f8a9c34a4ca 100644 --- a/packages/api/amplify_api/example/integration_test/util.dart +++ b/packages/api/amplify_api/example/integration_test/util.dart @@ -277,6 +277,24 @@ Future 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> listAllPages( + GraphQLRequest> request, +) async { + final items = []; + GraphQLRequest>? 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 deleteTestModels() async { await Future.wait(blogCache.map(deleteBlog)); await Future.wait(postCache.map(deletePost));