Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): Custom Selection Set with nested has-many missing nextToken #3161

Closed
wants to merge 1 commit into from
Closed
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 @@ -100,6 +100,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
}
__typename
}
nextToken
}
}
__typename
Expand Down Expand Up @@ -161,6 +162,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
}
__typename
}
nextToken
}
}
__typename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,6 +60,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest {
}
__typename
}
nextToken
}
implicitChildren {
items {
Expand All @@ -74,6 +75,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest {
}
__typename
}
nextToken
}
strangeChildren {
items {
Expand All @@ -88,6 +90,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest {
}
__typename
}
nextToken
}
childrenSansBelongsTo {
items {
Expand All @@ -99,6 +102,7 @@ final class GraphQLLazyLoadCompositePKTests: GraphQLLazyLoadBaseTest {
updatedAt
__typename
}
nextToken
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ final class GraphQLLazyLoadPostCommentWithCompositeKeyTests: GraphQLLazyLoadBase
}
__typename
}
nextToken
}
}
__typename
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class IncludeAssociationDecoratorTests: XCTestCase {
}
__typename
}
nextToken
}
"""
let selectionSet = createSelectionSet(for: Post.self, includes: { post in [post.comments] })
Expand Down Expand Up @@ -217,6 +218,7 @@ class IncludeAssociationDecoratorTests: XCTestCase {
}
__typename
}
nextToken
}
"""
let selectionSet = createSelectionSet(for: Book.self, includes: { book in
Expand Down Expand Up @@ -271,6 +273,7 @@ class IncludeAssociationDecoratorTests: XCTestCase {
}
__typename
}
nextToken
}
"""
let selectionSet = createSelectionSet(for: Author.self, includes: { author in
Expand Down Expand Up @@ -310,6 +313,7 @@ class IncludeAssociationDecoratorTests: XCTestCase {
}
__typename
}
nextToken
}
"""
let selectionSet = createSelectionSet(for: Author.self, includes: { author in
Expand Down