Force creation of a new websocket for subscriptions when switching between APIs #7156
Labels
AppSync
Related to AppSync issues
feature-request
Request a new feature
GraphQL
Related to GraphQL API issues
Is your feature request related to a problem? Please describe.
My react client switches between 2 AppSync API endpoints using
Amplify.configure
When connecting to the first API everything works: mutations are effective and subscriptions receive updates.
But if I switch to the second API only mutations will work. Subscriptions will not receive any updates.
I tracked this down to amplify keeping the websocket connection alive for 1sec after unsubscribing, therefore re-using the first API's websocket connection for the second API's subscriptions.
PS: don't know if it's relevant but I'm using API_KEY for authentication.
Describe the solution you'd like
I would like to be able to force amplify to close existing websocket connections when calling
Amplify.configure
.Otherwise make sure that new subscriptions that use "old" websocket connections do get triggered.
Describe alternatives you've considered
For now I have to force my components to wait for a few seconds before creating subscriptions.
This gives amplify time to detect existing websockets timeout and close them, forcing a new websocket to be created.
This is quite hacky as I need to artificially go around the async nature of React.
Additional context
Some observations:
amplify-js/packages/pubsub/src/PubSub.ts
Line 45 in e1d122b
amplify-js/packages/pubsub/src/Providers/AWSAppSyncRealTimeProvider.ts
Line 386 in 61f7478
If given enough time between API endpoint switch, Amplify will create a new websocket connection.
In such case subscriptions will work for both endpoints:
Otherwise it will reuse the same connection for a different API endpoint
The text was updated successfully, but these errors were encountered: