@@ -117,19 +117,19 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest {
117
117
let child = DefaultPKChild ( )
118
118
let subscription = Amplify . API. subscribe ( request: . subscription( of: DefaultPKChild . self, type: . onCreate) )
119
119
Task {
120
- do {
121
- for try await subscriptionEvent in subscription {
122
- switch subscriptionEvent {
123
- case . connection ( . connected ) :
124
- await connected . fulfill ( )
125
- case let . data ( . success ( newModel ) ) :
126
- if newModel . identifier == child . identifier {
127
- await onCreate . fulfill ( )
128
- }
129
- case let . data ( . failure ( error ) ) :
130
- XCTFail ( " Failed to create DefaultPKChild, error: \( error . errorDescription ) " )
131
- default : ( )
132
- }
120
+ for try await subscriptionEvent in subscription {
121
+ if subscriptionEvent. isConnected ( ) {
122
+ await connected . fulfill ( )
123
+ }
124
+
125
+ if let error = subscriptionEvent . extractError ( ) {
126
+ XCTFail ( " Failed to create DefaultPKChild, error: \( error . errorDescription ) " )
127
+ }
128
+
129
+ if let data = subscriptionEvent . extractData ( ) ,
130
+ data . identifier == child . identifier
131
+ {
132
+ await onCreate . fulfill ( )
133
133
}
134
134
}
135
135
}
@@ -156,24 +156,24 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest {
156
156
let child = DefaultPKChild ( parent: parent)
157
157
let subscription = Amplify . API. subscribe ( request: . subscription( of: DefaultPKParent . self, type: . onCreate) )
158
158
Task {
159
- do {
160
- for try await subscriptionEvent in subscription {
161
- switch subscriptionEvent {
162
- case . connection ( . connected ) :
163
- await connected . fulfill ( )
164
- case let . data ( . success ( newModel ) ) :
165
- try await newModel . children ? . fetch ( )
166
- let associatedChilden = newModel . children ? . loadedState
167
- if newModel . identifier == parent . identifier ,
168
- case . some ( . loaded ( let associatedChilden ) ) = associatedChilden ,
169
- associatedChilden . map ( \ . identifier) . contains ( child . identifier )
170
- {
171
- await onCreate . fulfill ( )
172
- }
173
- case let . data ( . failure ( error ) ) :
174
- XCTFail ( " Failed to create DefaultPKParent, error: \( error . errorDescription ) " )
175
- default : ( )
176
- }
159
+ for try await subscriptionEvent in subscription {
160
+ if subscriptionEvent. isConnected ( ) {
161
+ await connected . fulfill ( )
162
+ }
163
+
164
+ if let error = subscriptionEvent . extractError ( ) {
165
+ XCTFail ( " Failed to create DefaultPKParent, error: \( error . errorDescription ) " )
166
+ }
167
+
168
+ guard let data = subscriptionEvent . extractData ( ) ,
169
+ data . identifier == parent . identifier
170
+ else { continue }
171
+
172
+ try await data . children ? . fetch ( )
173
+ if case . some ( . loaded ( let associatedChildren ) ) = data . children ? . loadedState ,
174
+ associatedChildren . map ( \ . identifier ) . contains ( child . identifier )
175
+ {
176
+ await onCreate . fulfill ( )
177
177
}
178
178
}
179
179
}
@@ -202,19 +202,19 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest {
202
202
let subscription = Amplify . API. subscribe ( request: . subscription( of: DefaultPKChild . self, type: . onUpdate) )
203
203
204
204
Task {
205
- do {
206
- for try await subscriptionEvent in subscription {
207
- switch subscriptionEvent {
208
- case . connection ( . connected ) :
209
- await connected . fulfill ( )
210
- case let . data ( . success ( newModel ) ) :
211
- if newModel . identifier == child . identifier {
212
- await onUpdate . fulfill ( )
213
- }
214
- case let . data ( . failure ( error ) ) :
215
- XCTFail ( " Failed to update DefaultPKChild, error: \( error . errorDescription ) " )
216
- default : ( )
217
- }
205
+ for try await subscriptionEvent in subscription {
206
+ if subscriptionEvent. isConnected ( ) {
207
+ await connected . fulfill ( )
208
+ }
209
+
210
+ if let error = subscriptionEvent . extractError ( ) {
211
+ XCTFail ( " Failed to update DefaultPKChild, error: \( error . errorDescription ) " )
212
+ }
213
+
214
+ if let data = subscriptionEvent . extractData ( ) ,
215
+ data . identifier == child . identifier
216
+ {
217
+ await onUpdate . fulfill ( )
218
218
}
219
219
}
220
220
}
@@ -250,25 +250,25 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest {
250
250
let subscription = Amplify . API. subscribe ( request: . subscription( of: DefaultPKParent . self, type: . onUpdate) )
251
251
252
252
Task {
253
- do {
254
- for try await subscriptionEvent in subscription {
255
- switch subscriptionEvent {
256
- case . connection ( . connected ) :
257
- await connected . fulfill ( )
258
- case let . data ( . success ( newModel ) ) :
259
- try await newModel . children ? . fetch ( )
260
- let associatedChilden = newModel . children ? . loadedState
261
- if newModel . identifier == parent . identifier ,
262
- case . some ( . loaded ( let associatedChilden ) ) = associatedChilden ,
263
- associatedChilden . map ( \ . identifier) . contains ( child . identifier ) ,
264
- associatedChilden . map ( \ . identifier ) . contains ( anotherChild . identifier )
265
- {
266
- await onUpdate . fulfill ( )
267
- }
268
- case let . data ( . failure ( error ) ) :
269
- XCTFail ( " Failed to update HasOneParent, error: \( error . errorDescription ) " )
270
- default : ( )
271
- }
253
+ for try await subscriptionEvent in subscription {
254
+ if subscriptionEvent. isConnected ( ) {
255
+ await connected . fulfill ( )
256
+ }
257
+
258
+ if let error = subscriptionEvent . extractError ( ) {
259
+ XCTFail ( " Failed to update DefaultPKParent, error: \( error . errorDescription ) " )
260
+ }
261
+
262
+ guard let data = subscriptionEvent . extractData ( ) ,
263
+ data . identifier == parent . identifier
264
+ else { continue }
265
+
266
+ try await data . children ? . fetch ( )
267
+ if case . some ( . loaded ( let associatedChildren ) ) = data . children ? . loadedState ,
268
+ associatedChildren . map ( \ . identifier ) . contains ( child . identifier ) ,
269
+ associatedChildren . map ( \ . identifier ) . contains ( anotherChild . identifier )
270
+ {
271
+ await onUpdate . fulfill ( )
272
272
}
273
273
}
274
274
}
@@ -301,19 +301,19 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest {
301
301
let subscription = Amplify . API. subscribe ( request: . subscription( of: DefaultPKChild . self, type: . onDelete) )
302
302
303
303
Task {
304
- do {
305
- for try await subscriptionEvent in subscription {
306
- switch subscriptionEvent {
307
- case . connection ( . connected ) :
308
- await connected . fulfill ( )
309
- case let . data ( . success ( newModel ) ) :
310
- if newModel . identifier == child . identifier {
311
- await onDelete . fulfill ( )
312
- }
313
- case let . data ( . failure ( error ) ) :
314
- XCTFail ( " Failed to delete DefaultPKChild, error: \( error . errorDescription ) " )
315
- default : ( )
316
- }
304
+ for try await subscriptionEvent in subscription {
305
+ if subscriptionEvent. isConnected ( ) {
306
+ await connected . fulfill ( )
307
+ }
308
+
309
+ if let error = subscriptionEvent . extractError ( ) {
310
+ XCTFail ( " Failed to delete DefaultPKChild, error: \( error . errorDescription ) " )
311
+ }
312
+
313
+ if let data = subscriptionEvent . extractData ( ) ,
314
+ data . identifier == child . identifier
315
+ {
316
+ await onDelete . fulfill ( )
317
317
}
318
318
}
319
319
}
@@ -344,24 +344,24 @@ final class GraphQLLazyLoadDefaultPKTests: GraphQLLazyLoadBaseTest {
344
344
let subscription = Amplify . API. subscribe ( request: . subscription( of: DefaultPKParent . self, type: . onDelete) )
345
345
346
346
Task {
347
- do {
348
- for try await subscriptionEvent in subscription {
349
- switch subscriptionEvent {
350
- case . connection ( . connected ) :
351
- await connected . fulfill ( )
352
- case let . data ( . success ( newModel ) ) :
353
- try await newModel . children ? . fetch ( )
354
- let associatedChilden = newModel . children ? . loadedState
355
- if newModel . identifier == parent . identifier ,
356
- case . some ( . loaded ( let associatedChildren ) ) = associatedChilden ,
357
- associatedChildren . map ( \ . identifier) . contains ( child . identifier )
358
- {
359
- await onDelete . fulfill ( )
360
- }
361
- case let . data ( . failure ( error ) ) :
362
- XCTFail ( " Failed to delete DefaultPKParent, error: \( error . errorDescription ) " )
363
- default : ( )
364
- }
347
+ for try await subscriptionEvent in subscription {
348
+ if subscriptionEvent. isConnected ( ) {
349
+ await connected . fulfill ( )
350
+ }
351
+
352
+ if let error = subscriptionEvent . extractError ( ) {
353
+ XCTFail ( " Failed to delete DefaultPKParent, error: \( error . errorDescription ) " )
354
+ }
355
+
356
+ guard let data = subscriptionEvent . extractData ( ) ,
357
+ data . identifier == parent . identifier
358
+ else { continue }
359
+
360
+ try await data . children ? . fetch ( )
361
+ if case . some ( . loaded ( let associatedChildren ) ) = data . children ? . loadedState ,
362
+ associatedChildren . map ( \ . identifier ) . contains ( child . identifier )
363
+ {
364
+ await onDelete . fulfill ( )
365
365
}
366
366
}
367
367
}
0 commit comments