@@ -73,19 +73,39 @@ final class IncomingAsyncSubscriptionEventPublisher: AmplifyCancellable {
73
73
74
74
// onCreate operation
75
75
let onCreateValueListener = onCreateValueListenerHandler ( event: )
76
- let onCreateAuthTypeProvider = await authModeStrategy. authTypesFor ( schema: modelSchema,
76
+ var onCreateAuthTypeProvider = await authModeStrategy. authTypesFor ( schema: modelSchema,
77
77
operations: [ . create, . read] )
78
+ var onCreateAuthType : AWSAuthorizationType ? = onCreateAuthTypeProvider. next ( )
79
+ var onCreateModelPredicate = modelPredicate
80
+
78
81
self . onCreateValueListener = onCreateValueListener
79
82
self . onCreateOperation = RetryableGraphQLSubscriptionOperation (
80
83
requestFactory: IncomingAsyncSubscriptionEventPublisher . apiRequestFactoryFor (
81
84
for: modelSchema,
82
- where: modelPredicate ,
85
+ where: { onCreateModelPredicate } ,
83
86
subscriptionType: . onCreate,
84
87
api: api,
85
88
auth: auth,
86
89
awsAuthService: self . awsAuthService,
87
- authTypeProvider: onCreateAuthTypeProvider ) ,
90
+ authTypeProvider: { onCreateAuthType } ) ,
88
91
maxRetries: onCreateAuthTypeProvider. count,
92
+ errorListener: { error in
93
+ // TODO: - How to distinguish errors?
94
+ // TODO: - Handle other errors
95
+ if error. debugDescription. contains ( " Filters combination exceed maximum limit 10 for subscription. " ) {
96
+ onCreateModelPredicate = nil
97
+
98
+ } else if case let . operationError( errorDescription, recoverySuggestion, underlyingError) = error,
99
+ let authError = underlyingError as? AuthError {
100
+
101
+ switch authError {
102
+ case . signedOut, . notAuthorized:
103
+ onCreateAuthType = onCreateAuthTypeProvider. next ( )
104
+ default :
105
+ return
106
+ }
107
+ }
108
+ } ,
89
109
resultListener: genericCompletionListenerHandler) { nextRequest, wrappedCompletion in
90
110
api. subscribe ( request: nextRequest,
91
111
valueListener: onCreateValueListener,
@@ -95,19 +115,39 @@ final class IncomingAsyncSubscriptionEventPublisher: AmplifyCancellable {
95
115
96
116
// onUpdate operation
97
117
let onUpdateValueListener = onUpdateValueListenerHandler ( event: )
98
- let onUpdateAuthTypeProvider = await authModeStrategy. authTypesFor ( schema: modelSchema,
118
+ var onUpdateAuthTypeProvider = await authModeStrategy. authTypesFor ( schema: modelSchema,
99
119
operations: [ . update, . read] )
120
+ var onUpdateAuthType : AWSAuthorizationType ? = onUpdateAuthTypeProvider. next ( )
121
+ var onUpdateModelPredicate = modelPredicate
122
+
100
123
self . onUpdateValueListener = onUpdateValueListener
101
124
self . onUpdateOperation = RetryableGraphQLSubscriptionOperation (
102
125
requestFactory: IncomingAsyncSubscriptionEventPublisher . apiRequestFactoryFor (
103
126
for: modelSchema,
104
- where: modelPredicate ,
127
+ where: { onUpdateModelPredicate } ,
105
128
subscriptionType: . onUpdate,
106
129
api: api,
107
130
auth: auth,
108
131
awsAuthService: self . awsAuthService,
109
- authTypeProvider: onUpdateAuthTypeProvider ) ,
132
+ authTypeProvider: { onUpdateAuthType } ) ,
110
133
maxRetries: onUpdateAuthTypeProvider. count,
134
+ errorListener: { error in
135
+ // TODO: - How to distinguish errors?
136
+ // TODO: - Handle other errors
137
+ if error. debugDescription. contains ( " Filters combination exceed maximum limit 10 for subscription. " ) {
138
+ onUpdateModelPredicate = nil
139
+
140
+ } else if case let . operationError( errorDescription, recoverySuggestion, underlyingError) = error,
141
+ let authError = underlyingError as? AuthError {
142
+
143
+ switch authError {
144
+ case . signedOut, . notAuthorized:
145
+ onUpdateAuthType = onUpdateAuthTypeProvider. next ( )
146
+ default :
147
+ return
148
+ }
149
+ }
150
+ } ,
111
151
resultListener: genericCompletionListenerHandler) { nextRequest, wrappedCompletion in
112
152
api. subscribe ( request: nextRequest,
113
153
valueListener: onUpdateValueListener,
@@ -117,19 +157,39 @@ final class IncomingAsyncSubscriptionEventPublisher: AmplifyCancellable {
117
157
118
158
// onDelete operation
119
159
let onDeleteValueListener = onDeleteValueListenerHandler ( event: )
120
- let onDeleteAuthTypeProvider = await authModeStrategy. authTypesFor ( schema: modelSchema,
160
+ var onDeleteAuthTypeProvider = await authModeStrategy. authTypesFor ( schema: modelSchema,
121
161
operations: [ . delete, . read] )
162
+ var onDeleteAuthType : AWSAuthorizationType ? = onDeleteAuthTypeProvider. next ( )
163
+ var onDeleteModelPredicate = modelPredicate
164
+
122
165
self . onDeleteValueListener = onDeleteValueListener
123
166
self . onDeleteOperation = RetryableGraphQLSubscriptionOperation (
124
167
requestFactory: IncomingAsyncSubscriptionEventPublisher . apiRequestFactoryFor (
125
168
for: modelSchema,
126
- where: modelPredicate ,
169
+ where: { onDeleteModelPredicate } ,
127
170
subscriptionType: . onDelete,
128
171
api: api,
129
172
auth: auth,
130
173
awsAuthService: self . awsAuthService,
131
- authTypeProvider: onDeleteAuthTypeProvider ) ,
174
+ authTypeProvider: { onDeleteAuthType } ) ,
132
175
maxRetries: onUpdateAuthTypeProvider. count,
176
+ errorListener: { error in
177
+ // TODO: - How to distinguish errors?
178
+ // TODO: - Handle other errors
179
+ if error. debugDescription. contains ( " Filters combination exceed maximum limit 10 for subscription. " ) {
180
+ onDeleteModelPredicate = nil
181
+
182
+ } else if case let . operationError( errorDescription, recoverySuggestion, underlyingError) = error,
183
+ let authError = underlyingError as? AuthError {
184
+
185
+ switch authError {
186
+ case . signedOut, . notAuthorized:
187
+ onDeleteAuthType = onDeleteAuthTypeProvider. next ( )
188
+ default :
189
+ return
190
+ }
191
+ }
192
+ } ,
133
193
resultListener: genericCompletionListenerHandler) { nextRequest, wrappedCompletion in
134
194
api. subscribe ( request: nextRequest,
135
195
valueListener: onDeleteValueListener,
@@ -204,6 +264,7 @@ final class IncomingAsyncSubscriptionEventPublisher: AmplifyCancellable {
204
264
auth: AuthCategoryBehavior ? ,
205
265
authType: AWSAuthorizationType ? ,
206
266
awsAuthService: AWSAuthServiceBehavior ) async -> GraphQLRequest < Payload > {
267
+
207
268
let request : GraphQLRequest < Payload >
208
269
if modelSchema. hasAuthenticationRules,
209
270
let _ = auth,
@@ -303,20 +364,20 @@ final class IncomingAsyncSubscriptionEventPublisher: AmplifyCancellable {
303
364
// MARK: - IncomingAsyncSubscriptionEventPublisher + API request factory
304
365
extension IncomingAsyncSubscriptionEventPublisher {
305
366
static func apiRequestFactoryFor( for modelSchema: ModelSchema ,
306
- where predicate: QueryPredicate ? ,
367
+ where predicate: @escaping ( ) -> QueryPredicate ? ,
307
368
subscriptionType: GraphQLSubscriptionType ,
308
369
api: APICategoryGraphQLBehaviorExtended ,
309
370
auth: AuthCategoryBehavior ? ,
310
371
awsAuthService: AWSAuthServiceBehavior ,
311
- authTypeProvider: AWSAuthorizationTypeIterator ) -> RetryableGraphQLOperation < Payload > . RequestFactory {
312
- var authTypes = authTypeProvider
372
+ authTypeProvider: @escaping ( ) -> AWSAuthorizationType ? ) -> RetryableGraphQLOperation < Payload > . RequestFactory {
373
+
313
374
return {
314
- return await IncomingAsyncSubscriptionEventPublisher . makeAPIRequest ( for: modelSchema,
315
- where: predicate,
375
+ await IncomingAsyncSubscriptionEventPublisher . makeAPIRequest ( for: modelSchema,
376
+ where: predicate ( ) ,
316
377
subscriptionType: subscriptionType,
317
378
api: api,
318
379
auth: auth,
319
- authType: authTypes . next ( ) ,
380
+ authType: authTypeProvider ( ) ,
320
381
awsAuthService: awsAuthService)
321
382
}
322
383
}
0 commit comments