Skip to content

Commit a825990

Browse files
committed
fix: do not set nil values for create mutation graphQL input translation (#2701)
* testing DataStore HasOneParentChild * add more testing * Add list query API integ tests * remove config comment * Add DS lazy load observeQuery tests * add API include nested models * fix: do not set nil values for create mutation graphQL input translation * fix hasOneParent test * fix DataStore LL5 testSaveProjectWithTeamThenAccessProjectFromTeam
1 parent 5333447 commit a825990

File tree

46 files changed

+5321
-471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5321
-471
lines changed

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/L13/GraphQLLazyLoadPhoneCallTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import AWSPluginsCore
1515
final class GraphQLLazyLoadPhoneCallTests: GraphQLLazyLoadBaseTest {
1616

1717
func testConfigure() async throws {
18-
await setup(withModels: PhoneCallModels(), logLevel: .verbose)
18+
await setup(withModels: PhoneCallModels())
1919
}
2020

2121
/// Saving a person should be successfully

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL1/GraphQLLazyLoadPostComment4V2Tests.swift

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
2525

2626
// Without `includes` and latest codegenerated types with the model path, the post should be lazy loaded
2727
func testCommentWithLazyLoadPost() async throws {
28-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
28+
await setup(withModels: PostComment4V2Models())
2929
let post = Post(title: "title")
3030
let comment = Comment(content: "content", post: post)
3131
let createdPost = try await mutate(.create(post))
@@ -49,7 +49,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
4949

5050
// With `includes` on `comment.post`, the comment's post should be eager loaded.
5151
func testCommentWithEagerLoadPost() async throws {
52-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
52+
await setup(withModels: PostComment4V2Models())
5353
let post = Post(title: "title")
5454
let comment = Comment(content: "content", post: post)
5555
let createdPost = try await mutate(.create(post))
@@ -70,7 +70,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
7070

7171
// With `includes` on `comment.post.comments`,
7272
func testCommentWithEagerLoadPostAndPostComments() async throws {
73-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
73+
await setup(withModels: PostComment4V2Models())
7474
let post = Post(title: "title")
7575
let comment = Comment(content: "content", post: post)
7676
let createdPost = try await mutate(.create(post))
@@ -119,7 +119,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
119119

120120
// This looks broken
121121
func testCommentWithEagerLoadPostAndPostCommentsAndPostCommentsPost() async throws {
122-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
122+
await setup(withModels: PostComment4V2Models())
123123
let post = Post(title: "title")
124124
let comment = Comment(content: "content", post: post)
125125
try await mutate(.create(post))
@@ -168,7 +168,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
168168

169169
// Without `includes` and latest codegenerated types with the model path, the post's comments should be lazy loaded
170170
func testPostWithLazyLoadComments() async throws {
171-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
171+
await setup(withModels: PostComment4V2Models())
172172
let post = Post(title: "title")
173173
let comment = Comment(content: "content", post: post)
174174
_ = try await mutate(.create(post))
@@ -183,7 +183,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
183183

184184
// With `includes` on `post.comments` should eager load the post's comments
185185
func testPostWithEagerLoadComments() async throws {
186-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
186+
await setup(withModels: PostComment4V2Models())
187187
let post = Post(title: "title")
188188
let comment = Comment(content: "content", post: post)
189189
_ = try await mutate(.create(post))
@@ -196,7 +196,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
196196

197197
// With `includes` on `post.comments.post` should eager load the post's comments' post
198198
func testPostWithEagerLoadCommentsAndPost() async throws {
199-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
199+
await setup(withModels: PostComment4V2Models())
200200
let post = Post(title: "title")
201201
let comment = Comment(content: "content", post: post)
202202
let createdPost = try await mutate(.create(post))
@@ -207,8 +207,26 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
207207
assertLazyReference(comments.first!._post, state: .loaded(model: createdPost))
208208
}
209209

210+
func testListPostsListComments() async throws {
211+
await setup(withModels: PostComment4V2Models())
212+
let post = Post(title: "title")
213+
let comment = Comment(content: "content", post: post)
214+
try await mutate(.create(post))
215+
try await mutate(.create(comment))
216+
217+
let queriedPosts = try await listQuery(.list(Post.self, where: Post.keys.id == post.id))
218+
assertList(queriedPosts, state: .isLoaded(count: 1))
219+
assertList(queriedPosts.first!.comments!,
220+
state: .isNotLoaded(associatedIdentifiers: [post.id], associatedField: "post"))
221+
222+
let queriedComments = try await listQuery(.list(Comment.self, where: Comment.keys.id == comment.id))
223+
assertList(queriedComments, state: .isLoaded(count: 1))
224+
assertLazyReference(queriedComments.first!._post,
225+
state: .notLoaded(identifiers: [.init(name: "id", value: post.id)]))
226+
}
227+
210228
func testCreateWithoutPost() async throws {
211-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
229+
await setup(withModels: PostComment4V2Models())
212230
let comment = Comment(content: "content")
213231
try await mutate(.create(comment))
214232
var queriedComment = try await query(.get(Comment.self, byId: comment.id))!
@@ -224,7 +242,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
224242
}
225243

226244
func testUpdateToNewPost() async throws {
227-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
245+
await setup(withModels: PostComment4V2Models())
228246
let post = Post(title: "title")
229247
let comment = Comment(content: "content", post: post)
230248
try await mutate(.create(post))
@@ -243,7 +261,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
243261
}
244262

245263
func testUpdateRemovePost() async throws {
246-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
264+
await setup(withModels: PostComment4V2Models())
247265
let post = Post(title: "title")
248266
let comment = Comment(content: "content", post: post)
249267
try await mutate(.create(post))
@@ -258,7 +276,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
258276
}
259277

260278
func testDelete() async throws {
261-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
279+
await setup(withModels: PostComment4V2Models())
262280
let post = Post(title: "title")
263281
let comment = Comment(content: "content", post: post)
264282
let createdPost = try await mutate(.create(post))
@@ -275,7 +293,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
275293
}
276294

277295
func testSubscribeToComments() async throws {
278-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
296+
await setup(withModels: PostComment4V2Models())
279297
let post = Post(title: "title")
280298
try await mutate(.create(post))
281299
let connected = asyncExpectation(description: "subscription connected")
@@ -316,7 +334,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
316334
// The identical `includes` parameter should be used because the selection set of the mutation
317335
// has to match the selection set of the subscription.
318336
func testSubscribeToCommentsIncludesPost() async throws {
319-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
337+
await setup(withModels: PostComment4V2Models())
320338
let post = Post(title: "title")
321339
try await mutate(.create(post))
322340
let connected = asyncExpectation(description: "subscription connected")
@@ -357,7 +375,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
357375
}
358376

359377
func testSubscribeToPosts() async throws {
360-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
378+
await setup(withModels: PostComment4V2Models())
361379
let post = Post(title: "title")
362380

363381
let connected = asyncExpectation(description: "subscription connected")
@@ -395,7 +413,7 @@ final class GraphQLLazyLoadPostComment4V2Tests: GraphQLLazyLoadBaseTest {
395413
}
396414

397415
func testSubscribeToPostsIncludes() async throws {
398-
await setup(withModels: PostComment4V2Models(), logLevel: .verbose)
416+
await setup(withModels: PostComment4V2Models())
399417
let post = Post(title: "title")
400418

401419
let connected = asyncExpectation(description: "subscription connected")

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/LL10/GraphQLLazyLoadPostComment7Tests.swift

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import AWSPluginsCore
1515
final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
1616

1717
func testSave() async throws {
18-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
18+
await setup(withModels: PostComment7Models())
1919

2020
let post = Post(postId: UUID().uuidString, title: "title")
2121
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
22-
let savedPost = try await mutate(.create(post))
23-
let savedComment = try await mutate(.create(comment))
22+
try await mutate(.create(post))
23+
try await mutate(.create(comment))
2424
}
2525

2626
// Without `includes` and latest codegenerated types with the model path, the post should be lazy loaded
2727
func testCommentWithLazyLoadPost() async throws {
28-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
28+
await setup(withModels: PostComment7Models())
2929
let post = Post(postId: UUID().uuidString, title: "title")
3030
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
3131
let createdPost = try await mutate(.create(post))
@@ -52,7 +52,7 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
5252

5353
// With `includes` on `comment.post`, the comment's post should be eager loaded.
5454
func testCommentWithEagerLoadPost() async throws {
55-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
55+
await setup(withModels: PostComment7Models())
5656
let post = Post(postId: UUID().uuidString, title: "title")
5757
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
5858
let createdPost = try await mutate(.create(post))
@@ -73,8 +73,7 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
7373
}
7474

7575
func testQueryThenLazyLoad() async throws {
76-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
77-
76+
await setup(withModels: PostComment7Models())
7877
let post = Post(postId: UUID().uuidString, title: "title")
7978
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
8079
let savedPost = try await mutate(.create(post))
@@ -88,6 +87,26 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
8887
try await assertPost(queriedPost, canLazyLoad: savedComment)
8988
}
9089

90+
func testListPostsListComments() async throws {
91+
await setup(withModels: PostComment7Models())
92+
let post = Post(postId: UUID().uuidString, title: "title")
93+
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
94+
try await mutate(.create(post))
95+
try await mutate(.create(comment))
96+
97+
let queriedPosts = try await listQuery(.list(Post.self, where: Post.keys.postId == post.postId))
98+
assertList(queriedPosts, state: .isLoaded(count: 1))
99+
assertList(queriedPosts.first!.comments!,
100+
state: .isNotLoaded(associatedIdentifiers: [post.postId, post.title], associatedField: "post"))
101+
102+
let queriedComments = try await listQuery(.list(Comment.self, where: Comment.keys.commentId == comment.commentId))
103+
assertList(queriedComments, state: .isLoaded(count: 1))
104+
assertLazyReference(queriedComments.first!._post,
105+
state: .notLoaded(identifiers: [
106+
.init(name: "postId", value: post.postId),
107+
.init(name: "title", value: "title")]))
108+
}
109+
91110
func assertComment(_ comment: Comment,
92111
hasEagerLoaded post: Post) async throws {
93112
assertLazyReference(comment._post,
@@ -135,7 +154,7 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
135154
}
136155

137156
func testSaveWithoutPost() async throws {
138-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
157+
await setup(withModels: PostComment7Models())
139158
let comment = Comment(commentId: UUID().uuidString, content: "content")
140159
let savedComment = try await mutate(.create(comment))
141160
var queriedComment = try await query(.get(Comment.self, byIdentifier: .identifier(commentId: comment.commentId,
@@ -151,7 +170,7 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
151170
}
152171

153172
func testUpdateFromQueriedComment() async throws {
154-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
173+
await setup(withModels: PostComment7Models())
155174
let post = Post(postId: UUID().uuidString, title: "title")
156175
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
157176
let savedPost = try await mutate(.create(post))
@@ -166,7 +185,7 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
166185
}
167186

168187
func testUpdateToNewPost() async throws {
169-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
188+
await setup(withModels: PostComment7Models())
170189

171190
let post = Post(postId: UUID().uuidString, title: "title")
172191
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
@@ -186,7 +205,7 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
186205
}
187206

188207
func testUpdateRemovePost() async throws {
189-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
208+
await setup(withModels: PostComment7Models())
190209

191210
let post = Post(postId: UUID().uuidString, title: "title")
192211
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)
@@ -204,7 +223,7 @@ final class GraphQLLazyLoadPostComment7Tests: GraphQLLazyLoadBaseTest {
204223
}
205224

206225
func testDelete() async throws {
207-
await setup(withModels: PostComment7Models(), logLevel: .verbose)
226+
await setup(withModels: PostComment7Models())
208227

209228
let post = Post(postId: UUID().uuidString, title: "title")
210229
let comment = Comment(commentId: UUID().uuidString, content: "content", post: post)

0 commit comments

Comments
 (0)