diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL1/GraphQLLazyLoadPostComment4V2Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL1/GraphQLLazyLoadPostComment4V2Tests.swift index b429374f27..ecbb9ee959 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL1/GraphQLLazyLoadPostComment4V2Tests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL1/GraphQLLazyLoadPostComment4V2Tests.swift @@ -100,6 +100,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest { } __typename } + nextToken } } __typename @@ -161,6 +162,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest { } __typename } + nextToken } } __typename diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift index 9f7e8bbf74..c9602bfc9b 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL12/CompositePK/GraphQLLazyLoadCompositePKTests.swift @@ -40,8 +40,8 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest { [parent.children, parent.implicitChildren, parent.strangeChildren, parent.childrenSansBelongsTo] }) let expectedDocument = """ - query GetCompositePKParent($content: String!, $customId: ID!) { - getCompositePKParent(content: $content, customId: $customId) { + query GetCompositePKParent { + getCompositePKParent(content: "content", customId: "\(savedParent.customId)") { customId content createdAt @@ -60,6 +60,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest { } __typename } + nextToken } implicitChildren { items { @@ -74,6 +75,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest { } __typename } + nextToken } strangeChildren { items { @@ -88,6 +90,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest { } __typename } + nextToken } childrenSansBelongsTo { items { @@ -99,6 +102,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest { updatedAt __typename } + nextToken } } } diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL3/GraphQLLazyLoadPostCommentWithCompositeKeyTests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL3/GraphQLLazyLoadPostCommentWithCompositeKeyTests.swift index af57158bc3..0a1359c8c1 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL3/GraphQLLazyLoadPostCommentWithCompositeKeyTests.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL3/GraphQLLazyLoadPostCommentWithCompositeKeyTests.swift @@ -104,6 +104,7 @@ final class GraphQLLazyLoadPostCommentWithCompositeKeyTests: GraphQLLazyLoadBase } __typename } + nextToken } } __typename @@ -168,6 +169,28 @@ final class GraphQLLazyLoadPostCommentWithCompositeKeyTests: GraphQLLazyLoadBase assertLazyReference(comments.first!._post, state: .loaded(model: createdPost)) } + func testListPostsThenFetchComments() async throws { + await setup(withModels: PostCommentWithCompositeKeyModels()) + let post = Post(title: "title") + let comment = Comment(content: "content", post: post) + try await mutate(.create(post)) + try await mutate(.create(comment)) + + let queriedPosts = try await listQuery(.list(Post.self, where: Post.keys.id == post.id)) + assertList(queriedPosts, state: .isLoaded(count: 1)) + var comments = queriedPosts.first!.comments! + assertList(comments, + state: .isNotLoaded(associatedIdentifiers: [post.id, post.title], associatedFields: ["post"])) + try await comments.fetch() + var allComments = comments.elements + while comments.hasNextPage() { + let nextPage = try await comments.getNextPage() + allComments.append(contentsOf: nextPage.elements) + comments = nextPage + } + XCTAssertEqual(allComments.count, 1) + } + func testListPostsListComments() async throws { await setup(withModels: PostCommentWithCompositeKeyModels()) let post = Post(title: "title") diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift index 61ab94efe8..923780c3cf 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift @@ -129,6 +129,7 @@ extension SelectionSet { result.append(innerSelectionSetField.stringValue(indentSize: indentSize + 2)) } result.append(doubleIndent + "}") + result.append(doubleIndent + "nextToken") result.append(indent + "}") case .value: guard let name = value.name else { diff --git a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/IncludeAssociationDecoratorTests.swift b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/IncludeAssociationDecoratorTests.swift index a2098a2a69..b1d4b768b6 100644 --- a/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/IncludeAssociationDecoratorTests.swift +++ b/AmplifyPlugins/Core/AWSPluginsCoreTests/Model/Decorator/IncludeAssociationDecoratorTests.swift @@ -165,6 +165,7 @@ class IncludeAssociationDecoratorTests: XCTestCase { } __typename } + nextToken } """ let selectionSet = createSelectionSet(for: Post.self, includes: { post in [post.comments] }) @@ -217,6 +218,7 @@ class IncludeAssociationDecoratorTests: XCTestCase { } __typename } + nextToken } """ let selectionSet = createSelectionSet(for: Book.self, includes: { book in @@ -271,6 +273,7 @@ class IncludeAssociationDecoratorTests: XCTestCase { } __typename } + nextToken } """ let selectionSet = createSelectionSet(for: Author.self, includes: { author in @@ -310,6 +313,7 @@ class IncludeAssociationDecoratorTests: XCTestCase { } __typename } + nextToken } """ let selectionSet = createSelectionSet(for: Author.self, includes: { author in